summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarkus Grüneis <gimpf@gimpf.org>2014-10-24 15:17:33 +0200
committerMarkus Grüneis <gimpf@gimpf.org>2014-10-24 15:17:33 +0200
commit2682883d632aa06279eb408c4b668f6d5fa00017 (patch)
tree22bbb7738257dbb989ed1fa9c664e3ac34e85c51 /src
parenthub: Show usage when having arg -help (diff)
hub: Fix query for GetUpdatesAfter(id)
Diffstat (limited to 'src')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store.go17
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store_test.go24
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5typesApi.go15
3 files changed, 44 insertions, 12 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go
index fa0ba3a..9abbaea 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store.go
@@ -115,7 +115,8 @@ func isEmptyFilter(filter *StatsFilter) bool {
filter.contentId == nil &&
filter.format == nil &&
filter.quality == nil &&
- (filter.tagsAny == nil || len(filter.tagsAny) == 0) {
+ (filter.tagsAny == nil || len(filter.tagsAny) == 0) &&
+ filter.afterUpdateId == nil {
return true
}
return false
@@ -157,6 +158,12 @@ func getFilteredDataUpdateSelect(filter *StatsFilter) (string, map[string]interf
parameters["filterend"] = filter.end.Unix()
needsAnd = true
}
+ if filter.afterUpdateId != nil {
+ query += insertAnd(&needsAnd)
+ query += " " + dataUpdatesTn + ".Id > :afterUpdateId"
+ parameters["afterUpdateId"] = *filter.afterUpdateId
+ needsAnd = true
+ }
// TODO other fields
query += ")"
@@ -356,10 +363,10 @@ var (
)
func (s sqliteStore) GetUpdatesAfter(id int) (res []StatisticsData, err error) {
- updates, err := s.db.Select(
- dataUpdateQueryResult{},
- "SELECT "+updateColumnSelect+" FROM "+dataUpdatesTn+","+sourcesTn+" ON "+dataUpdatesTn+".SourceId = "+sourcesTn+".Id WHERE "+dataUpdatesTn+".Id > ?",
- id)
+ sourceSql, parameters := getFilteredDataUpdateSelect(&StatsFilter{afterUpdateId: &id})
+ sql := "SELECT " + updateColumnSelect + " FROM " + sourceSql
+ updates, err := s.db.Select(dataUpdateQueryResult{}, sql, parameters)
+ s5tl.Printf("sql: %s", sql)
if err == nil {
res = make([]StatisticsData, len(updates))
for i := range updates {
diff --git a/src/hub/src/spreadspace.org/sfive/s5store_test.go b/src/hub/src/spreadspace.org/sfive/s5store_test.go
index ed49175..49ca35e 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store_test.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store_test.go
@@ -65,3 +65,27 @@ func TestCount(t *testing.T) {
t.Errorf("Failed to count correctly.")
}
}
+
+func TestGetUpdatesAfter(t *testing.T) {
+ store, err := NewStore("file:memdb1?mode=memory&cache=shared")
+ if err != nil {
+ t.Errorf("Failed to initialize: %v", err)
+ return
+ }
+ defer store.Close()
+
+ startTime := time.Date(2014, time.August, 24, 14, 35, 33, 847282000, time.UTC)
+ update := DataUpdate{Data: SourceData{BytesSent: 1, ClientCount: 3, BytesReceived: 1}, StartTime: startTime, Duration: 5 * time.Millisecond}
+ streamId := StreamId{ContentId: "content", Format: "7bitascii", Quality: QualityHigh}
+ source := SourceId{Hostname: "localhost", Tags: []string{"tag1", "master"}, StreamId: streamId, Version: 1}
+ dat := StatisticsData{nil, nil, source, update}
+
+ err = store.Append(dat)
+ if err != nil {
+ t.Errorf("Failed to append: %v", err)
+ return
+ }
+
+ res, err := store.GetUpdatesAfter(2)
+ t.Logf("got updates (err %v):\n%#v", err, res)
+}
diff --git a/src/hub/src/spreadspace.org/sfive/s5typesApi.go b/src/hub/src/spreadspace.org/sfive/s5typesApi.go
index ac89b0c..bc32eb9 100644
--- a/src/hub/src/spreadspace.org/sfive/s5typesApi.go
+++ b/src/hub/src/spreadspace.org/sfive/s5typesApi.go
@@ -56,13 +56,14 @@ type StatisticsDataContainer struct {
}
type StatsFilter struct {
- start *time.Time
- end *time.Time
- hostname *string
- contentId *string
- format *string
- quality *string
- tagsAny []string
+ start *time.Time
+ end *time.Time
+ hostname *string
+ contentId *string
+ format *string
+ quality *string
+ tagsAny []string
+ afterUpdateId *int
}
func (self *StatisticsData) CopyFromSourceId(id *SourceId) {