diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5store.go | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go index 567cadc..75b9bb7 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store.go +++ b/src/hub/src/spreadspace.org/sfive/s5store.go @@ -278,7 +278,7 @@ func (st Store) insertNewUserAgent(tx *bolt.Tx, ua string) (uaId int, err error) return uaId, err } -func (st Store) insertClient(tx *bolt.Tx, duId int, cd []Client) error { +func (st Store) insertClient(tx *bolt.Tx, uId int, cd []Client) error { if len(cd) == 0 { return nil } @@ -299,44 +299,44 @@ func (st Store) insertClient(tx *bolt.Tx, duId int, cd []Client) error { if err != nil { return err } - return b.Put(itob(duId), jsonData) + return b.Put(itob(uId), jsonData) } -func (st Store) setLastUpdateForUuid(tx *bolt.Tx, uuid string, duId int) error { +func (st Store) setLastUpdateForUuid(tx *bolt.Tx, uuid string, uId int) error { b := tx.Bucket([]byte(latestUpdatesBn)) b.FillPercent = 1.0 // we only do appends last := b.Get([]byte(uuid)) - if last != nil && btoi(last) > duId { + if last != nil && btoi(last) > uId { return nil } - return b.Put([]byte(uuid), itob(duId)) + return b.Put([]byte(uuid), itob(uId)) } // Split up the multidimensional dataupdate and append all the key-value pairs -func (st Store) appendItem(tx *bolt.Tx, update UpdateFull) (duId int, err error) { - du := NewUpdateDb(update) - src := NewSourceDb(update) +func (st Store) appendItem(tx *bolt.Tx, uf UpdateFull) (uId int, err error) { + u := NewUpdateDb(uf) + s := NewSourceDb(uf) - if du.SourceHubId, err = st.insertNewHub(tx, update.SourceHubUuid); err != nil { + if u.SourceHubId, err = st.insertNewHub(tx, uf.SourceHubUuid); err != nil { return } - if du.SourceId, err = st.insertNewSource(tx, src); err != nil { + if u.SourceId, err = st.insertNewSource(tx, s); err != nil { return } - if duId, err = st.insertUpdate(tx, du); err != nil { + if uId, err = st.insertUpdate(tx, u); err != nil { return } - if err = st.insertClient(tx, duId, update.Data.Clients); err != nil { + if err = st.insertClient(tx, uId, uf.Data.Clients); err != nil { return } - if update.SourceHubUuid != "" { - err = st.setLastUpdateForUuid(tx, update.SourceHubUuid, du.SourceHubUpdateId) + if uf.SourceHubUuid != "" { + err = st.setLastUpdateForUuid(tx, uf.SourceHubUuid, u.SourceHubUpdateId) } - if update.ForwardHubUuid != "" { - err = st.setLastUpdateForUuid(tx, update.ForwardHubUuid, update.ForwardHubUpdateId) + if uf.ForwardHubUuid != "" { + err = st.setLastUpdateForUuid(tx, uf.ForwardHubUuid, uf.ForwardHubUpdateId) } return } @@ -376,7 +376,7 @@ func (st Store) getHub(tx *bolt.Tx, id int) string { return string(uuid) } -func (st Store) getSource(tx *bolt.Tx, id int) (res sourceDb, err error) { +func (st Store) getSource(tx *bolt.Tx, id int) (source sourceDb, err error) { b := tx.Bucket([]byte(sourcesRevBn)) jsonData := b.Get(itob(id)) @@ -384,13 +384,13 @@ func (st Store) getSource(tx *bolt.Tx, id int) (res sourceDb, err error) { err = ErrSourceNotFound return } - if err = json.Unmarshal(jsonData, &res); err != nil { + if err = json.Unmarshal(jsonData, &source); err != nil { return } return } -func (st Store) getClients(tx *bolt.Tx, id int) (res []Client, err error) { +func (st Store) getClients(tx *bolt.Tx, id int) (clients []Client, err error) { bc := tx.Bucket([]byte(clientDataBn)) bu := tx.Bucket([]byte(userAgentsRevBn)) @@ -408,21 +408,21 @@ func (st Store) getClients(tx *bolt.Tx, id int) (res []Client, err error) { if ua != nil { cd.UserAgent = string(ua) } - res = append(res, cd) + clients = append(clients, cd) } return } // fetch all the key-value pairs and merge them into the multidimensional dataupdate -func (st Store) fetchItem(tx *bolt.Tx, duId int, du updateDb) (res UpdateFull, err error) { - res.CopyFromUpdateDb(du, st.getHub(tx, du.SourceHubId), st.hubUuid, duId) +func (st Store) fetchItem(tx *bolt.Tx, uId int, u updateDb) (updates UpdateFull, err error) { + updates.CopyFromUpdateDb(u, st.getHub(tx, u.SourceHubId), st.hubUuid, uId) var src sourceDb - if src, err = st.getSource(tx, du.SourceId); err != nil { + if src, err = st.getSource(tx, u.SourceId); err != nil { return } - res.CopyFromSourceDb(src) - if res.Data.Clients, err = st.getClients(tx, duId); err != nil { + updates.CopyFromSourceDb(src) + if updates.Data.Clients, err = st.getClients(tx, uId); err != nil { return } return @@ -430,8 +430,8 @@ func (st Store) fetchItem(tx *bolt.Tx, duId int, du updateDb) (res UpdateFull, e // Public Fetch Interface -func (st Store) GetUpdatesAfter(id, limit int) (res []UpdateFull, err error) { - res = []UpdateFull{} +func (st Store) GetUpdatesAfter(id, limit int) (updates []UpdateFull, err error) { + updates = []UpdateFull{} if id < 0 { // TODO: interpret negative values as last x values id = 0 } @@ -460,8 +460,8 @@ func (st Store) GetUpdatesAfter(id, limit int) (res []UpdateFull, err error) { if err != nil { return err } - res = append(res, duf) - if len(res) >= limit { + updates = append(updates, duf) + if len(updates) >= limit { return nil } } @@ -470,7 +470,7 @@ func (st Store) GetUpdatesAfter(id, limit int) (res []UpdateFull, err error) { return } -func (st Store) GetUpdate(id int) (res UpdateFull, err error) { +func (st Store) GetUpdate(id int) (update UpdateFull, err error) { err = st.db.View(func(tx *bolt.Tx) error { b := tx.Bucket([]byte(updatesBn)) @@ -485,7 +485,7 @@ func (st Store) GetUpdate(id int) (res UpdateFull, err error) { } var err error - if res, err = st.fetchItem(tx, id, d); err != nil { + if update, err = st.fetchItem(tx, id, d); err != nil { return err } return nil @@ -525,20 +525,20 @@ func (st Store) GetLastUpdateIdForUuid(uuid string) (updateId int, err error) { return } -func (st Store) GetHubs() (res []string, err error) { - res = []string{st.hubUuid} +func (st Store) GetHubs() (hubs []string, err error) { + hubs = []string{st.hubUuid} err = st.db.View(func(tx *bolt.Tx) error { c := tx.Bucket([]byte(hubUuidsRevBn)).Cursor() for k, v := c.First(); k != nil; k, v = c.Next() { - res = append(res, string(v)) + hubs = append(hubs, string(v)) } return nil }) return } -func (st Store) GetSources() (res []Source, err error) { - res = []Source{} +func (st Store) GetSources() (sources []Source, err error) { + sources = []Source{} err = st.db.View(func(tx *bolt.Tx) error { c := tx.Bucket([]byte(sourcesRevBn)).Cursor() for k, v := c.First(); k != nil; k, v = c.Next() { @@ -548,7 +548,7 @@ func (st Store) GetSources() (res []Source, err error) { } var src Source src.CopyFromSourceDb(s) - res = append(res, src) + sources = append(sources, src) } return nil }) |