summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarkus Grüneis <gimpf@gimpf.org>2014-10-23 15:19:57 +0200
committerMarkus Grüneis <gimpf@gimpf.org>2014-10-23 15:19:57 +0200
commitb8a9728b759a527f581dcb42e947bfc5f9a383f9 (patch)
tree748b6aee0c78c4130428b065569f3c7b073f8ea2 /src
parenthub: Add per-DB UUID, optionally store in data-updates table (diff)
hub: Add query for last-update-id for given UUID to store, web.
Diffstat (limited to 'src')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srvWeb.go12
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store.go12
2 files changed, 24 insertions, 0 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
index 31964ad..fd9876b 100644
--- a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
+++ b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
@@ -165,6 +165,17 @@ func (self StatsSinkServer) postUpdate(c web.C, w http.ResponseWriter, r *http.R
// TODO send response channel, wait for OK
}
+func (self StatsSinkServer) getLastUpdateIdForUuid(c web.C, w http.ResponseWriter, r *http.Request) {
+ const resourceName = "lastupdateid"
+ id := c.URLParams["id"]
+ value, err := self.store.GetLastUpdateForUuid(id)
+ if err != nil {
+ http.Error(w, fmt.Sprintf("failed to retrieve %s: %v", resourceName, err), http.StatusInternalServerError)
+ return
+ }
+ fmt.Fprintf(w, "%s", value)
+}
+
func (self StatsSinkServer) getStats(c web.C, w http.ResponseWriter, r *http.Request) {
const resourceName = "stats"
filter := getFilter(r)
@@ -197,6 +208,7 @@ func (self StatsSinkServer) ServeWeb(vizAppLocation string) {
goji.Get("/updates", self.getUpdateList)
goji.Get("/updates/:id", self.getUpdate)
goji.Post("/updates", self.postUpdate)
+ goji.Get("/lastupdate/:id", self.getLastUpdateIdForUuid)
goji.Get("/stats", self.getStats)
goji.Handle("/viz/*", http.StripPrefix("/viz/", http.FileServer(http.Dir(vizAppLocation))))
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go
index 14d259f..49b70de 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store.go
@@ -361,6 +361,18 @@ func (s sqliteStore) GetUpdates(filter *StatsFilter) (res []StatisticsData, err
return
}
+func (s sqliteStore) GetLastUpdateForUuid(uuid string) (updateId int, err error) {
+ res, err := s.db.SelectInt(
+ "select max(SourceHubDataUpdateId) from "+dataUpdatesTn+" where SourceHubUuid = ?",
+ uuid)
+ if err == nil {
+ updateId = int(res)
+ } else {
+ s5l.Printf("db: failed to find max SourceHubDataUpdateId for %s: %v", uuid, err)
+ }
+ return
+}
+
func getCountEntriesSql() string {
return "count(*) as UpdateCount"
}