summaryrefslogtreecommitdiff
path: root/src/hub
diff options
context:
space:
mode:
Diffstat (limited to 'src/hub')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srvWeb.go23
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store.go52
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5typesApi.go1
3 files changed, 54 insertions, 22 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
index 67430c6..af9e986 100644
--- a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
+++ b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
@@ -104,6 +104,29 @@ func getFilter(r *http.Request) (filter StatsFilter) {
filter.quality = &quality
}
+ afterUpdateId := r.FormValue("afterUpdateId")
+ if afterUpdateId != "" {
+ id, err := strconv.ParseInt(afterUpdateId, 10, 32)
+ if err == nil {
+ idInt := int(id)
+ filter.afterUpdateId = &idInt
+ }
+ }
+
+ limit := r.FormValue("limit")
+ if limit != "" {
+ limitInt, err := strconv.ParseInt(limit, 10, 32)
+ if err == nil {
+ limitIntInt := int(limitInt)
+ filter.limit = &limitIntInt
+ }
+ }
+
+ sortOrder := r.FormValue("sortOrder")
+ if sortOrder != "" {
+ filter.sortOrder = &sortOrder
+ }
+
return
}
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go
index 569abc4..17ddbd1 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store.go
@@ -159,25 +159,33 @@ func getFilteredDataUpdateSelect(filter *StatsFilter) (string, map[string]interf
parameters := make(map[string]interface{})
needsAnd := false
- query += " WHERE"
-
- if filter.start != nil {
- query += insertAnd(&needsAnd)
- query += " StartTime >= :filterstart"
- parameters["filterstart"] = filter.start.Unix()
- needsAnd = true
- }
- if filter.end != nil {
- query += insertAnd(&needsAnd)
- query += " StartTime < :filterend"
- parameters["filterend"] = filter.end.Unix()
- needsAnd = true
- }
- if filter.afterUpdateId != nil {
- query += insertAnd(&needsAnd)
- query += " " + dataUpdatesTn + ".Id > :afterUpdateId"
- parameters["afterUpdateId"] = *filter.afterUpdateId
- needsAnd = true
+ if filter.start != nil || filter.end != nil || filter.afterUpdateId != nil {
+ query += " WHERE"
+
+ if filter.start != nil {
+ query += insertAnd(&needsAnd)
+ query += " StartTime >= :filterstart"
+ parameters["filterstart"] = filter.start.Unix()
+ needsAnd = true
+ }
+ if filter.end != nil {
+ query += insertAnd(&needsAnd)
+ query += " StartTime < :filterend"
+ parameters["filterend"] = filter.end.Unix()
+ needsAnd = true
+ }
+ if filter.afterUpdateId != nil {
+ query += insertAnd(&needsAnd)
+ query += " " + dataUpdatesTn + ".Id > :afterUpdateId"
+ parameters["afterUpdateId"] = *filter.afterUpdateId
+ needsAnd = true
+ }
+ }
+
+ if filter.sortOrder != nil {
+ if *filter.sortOrder == "desc" {
+ query += " ORDER BY " + dataUpdatesTn + ".Id DESC"
+ }
}
if filter.limit != nil {
query += " LIMIT :limit"
@@ -431,10 +439,10 @@ func (s sqliteStore) GetUpdatesAfter(id int) (res []StatisticsData, err error) {
func (s sqliteStore) GetUpdates(filter *StatsFilter) (res []StatisticsData, err error) {
sourceSql, parameters := getFilteredDataUpdateSelect(filter)
+ sql := "SELECT " + updateColumnSelect + " FROM " + sourceSql
+ s5tl.Printf("store: sql: %s", sql)
updates, err := s.db.Select(
- dataUpdateQueryResult{},
- "SELECT "+updateColumnSelect+" FROM "+sourceSql,
- parameters)
+ dataUpdateQueryResult{}, sql, parameters)
if err == nil {
res = make([]StatisticsData, len(updates))
for i := range updates {
diff --git a/src/hub/src/spreadspace.org/sfive/s5typesApi.go b/src/hub/src/spreadspace.org/sfive/s5typesApi.go
index c02e5b2..e3a397e 100644
--- a/src/hub/src/spreadspace.org/sfive/s5typesApi.go
+++ b/src/hub/src/spreadspace.org/sfive/s5typesApi.go
@@ -65,6 +65,7 @@ type StatsFilter struct {
tagsAny []string
afterUpdateId *int
limit *int
+ sortOrder *string
}
func (self *StatisticsData) CopyFromSourceId(id *SourceId) {