summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store.go76
1 files changed, 38 insertions, 38 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go
index 123fcd7..7891059 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store.go
@@ -69,7 +69,7 @@ func updateFromDataUpdateFull(value DataUpdateFull) (sourceDb, dataUpdateDb, []C
return src, du, cd
}
-func (s Store) insertNewSource(tx *bolt.Tx, src sourceDb) (srcId int, err error) {
+func (st Store) insertNewSource(tx *bolt.Tx, src sourceDb) (srcId int, err error) {
bf := tx.Bucket([]byte(sourcesFwdBn))
bf.FillPercent = 1.0 // we only do appends
br := tx.Bucket([]byte(sourcesRevBn))
@@ -98,7 +98,7 @@ func (s Store) insertNewSource(tx *bolt.Tx, src sourceDb) (srcId int, err error)
return srcId, err
}
-func (s Store) insertDataUpdate(tx *bolt.Tx, du dataUpdateDb) (duId int, err error) {
+func (st Store) insertDataUpdate(tx *bolt.Tx, du dataUpdateDb) (duId int, err error) {
b := tx.Bucket([]byte(dataUpdatesBn))
b.FillPercent = 1.0 // we only do appends
@@ -113,7 +113,7 @@ func (s Store) insertDataUpdate(tx *bolt.Tx, du dataUpdateDb) (duId int, err err
return
}
-func (s Store) insertNewUserAgent(tx *bolt.Tx, ua string) (uaId int, err error) {
+func (st Store) insertNewUserAgent(tx *bolt.Tx, ua string) (uaId int, err error) {
bf := tx.Bucket([]byte(userAgentsFwdBn))
bf.FillPercent = 1.0 // we only do appends
br := tx.Bucket([]byte(userAgentsRevBn))
@@ -136,7 +136,7 @@ func (s Store) insertNewUserAgent(tx *bolt.Tx, ua string) (uaId int, err error)
return uaId, err
}
-func (s Store) insertClientData(tx *bolt.Tx, duId int, cd []ClientData) error {
+func (st Store) insertClientData(tx *bolt.Tx, duId int, cd []ClientData) error {
if len(cd) == 0 {
return nil
}
@@ -146,7 +146,7 @@ func (s Store) insertClientData(tx *bolt.Tx, duId int, cd []ClientData) error {
data := []clientDataDb{}
for _, c := range cd {
- uaId, err := s.insertNewUserAgent(tx, c.UserAgent)
+ uaId, err := st.insertNewUserAgent(tx, c.UserAgent)
if err != nil {
return err
}
@@ -160,28 +160,28 @@ func (s Store) insertClientData(tx *bolt.Tx, duId int, cd []ClientData) error {
return b.Put(itob(duId), jsonData)
}
-func (s Store) appendItem(tx *bolt.Tx, src sourceDb, du dataUpdateDb, cd []ClientData) (err error) {
- if du.SourceId, err = s.insertNewSource(tx, src); err != nil {
+func (st Store) appendItem(tx *bolt.Tx, src sourceDb, du dataUpdateDb, cd []ClientData) (err error) {
+ if du.SourceId, err = st.insertNewSource(tx, src); err != nil {
return
}
var duId int
- if duId, err = s.insertDataUpdate(tx, du); err != nil {
+ if duId, err = st.insertDataUpdate(tx, du); err != nil {
return
}
- if err = s.insertClientData(tx, duId, cd); err != nil {
+ if err = st.insertClientData(tx, duId, cd); err != nil {
return
}
return
}
-func (s Store) AppendMany(updates []DataUpdateFull) (err error) {
- return s.db.Update(func(tx *bolt.Tx) error {
+func (st Store) AppendMany(updates []DataUpdateFull) (err error) {
+ return st.db.Update(func(tx *bolt.Tx) error {
for _, update := range updates {
src, du, cd := updateFromDataUpdateFull(update)
- if err := s.appendItem(tx, src, du, cd); err != nil {
+ if err := st.appendItem(tx, src, du, cd); err != nil {
return err
}
}
@@ -189,11 +189,11 @@ func (s Store) AppendMany(updates []DataUpdateFull) (err error) {
})
}
-func (s Store) Append(update DataUpdateFull) (err error) {
- return s.AppendMany([]DataUpdateFull{update})
+func (st Store) Append(update DataUpdateFull) (err error) {
+ return st.AppendMany([]DataUpdateFull{update})
}
-func (s Store) getSource(tx *bolt.Tx, id int) (res sourceDb, err error) {
+func (st Store) getSource(tx *bolt.Tx, id int) (res sourceDb, err error) {
b := tx.Bucket([]byte(sourcesRevBn))
jsonData := b.Get(itob(id))
@@ -207,9 +207,9 @@ func (s Store) getSource(tx *bolt.Tx, id int) (res sourceDb, err error) {
return
}
-func (s Store) GetSources() (res []SourceId, err error) {
+func (st Store) GetSources() (res []SourceId, err error) {
res = []SourceId{}
- err = s.db.View(func(tx *bolt.Tx) error {
+ 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() {
var s sourceDb
@@ -225,9 +225,9 @@ func (s Store) GetSources() (res []SourceId, err error) {
return
}
-func (s Store) GetSource(id int) (res SourceId, err error) {
- err = s.db.View(func(tx *bolt.Tx) error {
- src, err := s.getSource(tx, id)
+func (st Store) GetSource(id int) (res SourceId, err error) {
+ err = st.db.View(func(tx *bolt.Tx) error {
+ src, err := st.getSource(tx, id)
if err != nil {
return err
}
@@ -237,7 +237,7 @@ func (s Store) GetSource(id int) (res SourceId, err error) {
return
}
-func (s Store) getClientsByUpdateId(tx *bolt.Tx, id int) (res []ClientData, err error) {
+func (st Store) getClientsByUpdateId(tx *bolt.Tx, id int) (res []ClientData, err error) {
bc := tx.Bucket([]byte(clientDataBn))
bu := tx.Bucket([]byte(userAgentsRevBn))
@@ -260,17 +260,17 @@ func (s Store) getClientsByUpdateId(tx *bolt.Tx, id int) (res []ClientData, err
return
}
-func (s Store) createDataUpdateFullFromDb(tx *bolt.Tx, duId int, du dataUpdateDb) (res DataUpdateFull, err error) {
+func (st Store) createDataUpdateFullFromDb(tx *bolt.Tx, duId int, du dataUpdateDb) (res DataUpdateFull, err error) {
var clients []ClientData
- if clients, err = s.getClientsByUpdateId(tx, duId); err != nil {
+ if clients, err = st.getClientsByUpdateId(tx, duId); err != nil {
return
}
var src sourceDb
- if src, err = s.getSource(tx, du.SourceId); err != nil {
+ if src, err = st.getSource(tx, du.SourceId); err != nil {
return
}
- res.CopyFromDataUpdateDb(du, duId, s.hubId)
+ res.CopyFromDataUpdateDb(du, duId, st.hubId)
res.Hostname = src.Hostname
res.StreamId.ContentId = src.StreamId.ContentId
res.StreamId.Format = src.StreamId.Format
@@ -280,7 +280,7 @@ func (s Store) createDataUpdateFullFromDb(tx *bolt.Tx, duId int, du dataUpdateDb
return
}
-func (s Store) GetUpdatesAfter(id, limit int) (res []DataUpdateFull, err error) {
+func (st Store) GetUpdatesAfter(id, limit int) (res []DataUpdateFull, err error) {
res = []DataUpdateFull{}
if id < 0 { // TODO: interpret negative values as last x values
id = 0
@@ -289,7 +289,7 @@ func (s Store) GetUpdatesAfter(id, limit int) (res []DataUpdateFull, err error)
s5l.Printf("store: truncating get-update limit to %d (from %d)", StoreGetUpdatesLimit, limit)
limit = StoreGetUpdatesLimit
}
- err = s.db.View(func(tx *bolt.Tx) error {
+ err = st.db.View(func(tx *bolt.Tx) error {
c := tx.Bucket([]byte(dataUpdatesBn)).Cursor()
if k, _ := c.Seek(itob(id)); k == nil {
return nil
@@ -301,7 +301,7 @@ func (s Store) GetUpdatesAfter(id, limit int) (res []DataUpdateFull, err error)
}
var duf DataUpdateFull
- duf, err := s.createDataUpdateFullFromDb(tx, btoi(k), d)
+ duf, err := st.createDataUpdateFullFromDb(tx, btoi(k), d)
if err != nil {
return err
}
@@ -315,8 +315,8 @@ func (s Store) GetUpdatesAfter(id, limit int) (res []DataUpdateFull, err error)
return
}
-func (s Store) GetUpdate(id int) (res DataUpdateFull, err error) {
- err = s.db.View(func(tx *bolt.Tx) error {
+func (st Store) GetUpdate(id int) (res DataUpdateFull, err error) {
+ err = st.db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(dataUpdatesBn))
jsonData := b.Get(itob(id))
@@ -330,7 +330,7 @@ func (s Store) GetUpdate(id int) (res DataUpdateFull, err error) {
}
var err error
- if res, err = s.createDataUpdateFullFromDb(tx, id, d); err != nil {
+ if res, err = st.createDataUpdateFullFromDb(tx, id, d); err != nil {
return err
}
return nil
@@ -338,22 +338,22 @@ func (s Store) GetUpdate(id int) (res DataUpdateFull, err error) {
return
}
-func (s Store) GetLastUpdateForUuid(uuid string) (updateId int, err error) {
+func (st Store) GetLastUpdateForUuid(uuid string) (updateId int, err error) {
// TODO: implement me!
updateId = 0
return
}
-func (s Store) GetLastUpdateId() (updateId int, err error) {
- err = s.db.View(func(tx *bolt.Tx) error {
+func (st Store) GetLastUpdateId() (updateId int, err error) {
+ err = st.db.View(func(tx *bolt.Tx) error {
updateId = int(tx.Bucket([]byte(dataUpdatesBn)).Sequence())
return nil
})
return
}
-func (s Store) GetStoreId() string {
- return s.hubId
+func (st Store) GetStoreId() string {
+ return st.hubId
}
func NewStore(dbPath string) (Store, error) {
@@ -365,7 +365,7 @@ func NewStore(dbPath string) (Store, error) {
return Store{hubid, db}, nil
}
-func (s Store) Close() {
+func (st Store) Close() {
s5l.Printf("store: closing")
- s.db.Close()
+ st.db.Close()
}