summaryrefslogtreecommitdiff
path: root/src/hub
diff options
context:
space:
mode:
Diffstat (limited to 'src/hub')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srv.go16
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store.go44
2 files changed, 46 insertions, 14 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srv.go b/src/hub/src/spreadspace.org/sfive/s5srv.go
index a734ec1..1839419 100644
--- a/src/hub/src/spreadspace.org/sfive/s5srv.go
+++ b/src/hub/src/spreadspace.org/sfive/s5srv.go
@@ -1,10 +1,11 @@
package sfive
type StatsSinkServer struct {
- store sqliteStore
- quit chan bool
- done chan bool
- appendData chan StatisticsData
+ store sqliteStore
+ quit chan bool
+ done chan bool
+ appendData chan StatisticsData
+ appendManyData chan []StatisticsData
}
func (self StatsSinkServer) appendActor() {
@@ -18,6 +19,11 @@ func (self StatsSinkServer) appendActor() {
if err != nil {
s5l.Printf("failed to store data: %v\n", err)
}
+ case values := <-self.appendManyData:
+ err := self.store.AppendMany(values)
+ if err != nil {
+ s5l.Printf("failed to store many data: %v\n", err)
+ }
}
}
}
@@ -28,6 +34,7 @@ func (self StatsSinkServer) Close() {
close(self.quit)
close(self.done)
close(self.appendData)
+ close(self.appendManyData)
self.store.Close()
}
@@ -42,6 +49,7 @@ func NewServer(dbPath string) (server *StatsSinkServer, err error) {
server.quit = make(chan bool)
server.done = make(chan bool)
server.appendData = make(chan StatisticsData, 100)
+ server.appendManyData = make(chan []StatisticsData, 5)
go server.appendActor()
return
}
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go
index 9abbaea..efd459e 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store.go
@@ -268,16 +268,7 @@ func (s sqliteStore) insertDataUpdateClientEntries(cd []clientDataDb, du dataUpd
return
}
-// this function is the biggest pile of copy/pasted crap while sick that is still compilable.
-func (s sqliteStore) Append(update StatisticsData) (err error) {
- du, cd, src, tags := updateFromStatisticsData(update)
-
- // s.db.TraceOn("", log.New(os.Stdout, "gorptest: ", log.Lmicroseconds))
- tx, err := s.db.Begin()
- if err != nil {
- return
- }
-
+func (s sqliteStore) appendItem(du dataUpdateDb, cd []clientDataDb, src sourceDb, tags []tagDb) (err error) {
err = s.insertNewTags(tags)
if err != nil {
return
@@ -304,6 +295,39 @@ func (s sqliteStore) Append(update StatisticsData) (err error) {
return
}
+ return
+}
+
+// this function is the biggest pile of copy/pasted crap while sick that is still compilable.
+func (s sqliteStore) Append(update StatisticsData) (err error) {
+ tx, err := s.db.Begin()
+ if err != nil {
+ return
+ }
+
+ du, cd, src, tags := updateFromStatisticsData(update)
+ err = s.appendItem(du, cd, src, tags)
+ if err != nil {
+ return
+ }
+
+ return tx.Commit()
+}
+
+func (s sqliteStore) AppendMany(updates []StatisticsData) (err error) {
+ tx, err := s.db.Begin()
+ if err != nil {
+ return
+ }
+
+ for _, update := range updates {
+ du, cd, src, tags := updateFromStatisticsData(update)
+ err = s.appendItem(du, cd, src, tags)
+ if err != nil {
+ return
+ }
+ }
+
return tx.Commit()
}