From b8a9728b759a527f581dcb42e947bfc5f9a383f9 Mon Sep 17 00:00:00 2001 From: Markus Grüneis Date: Thu, 23 Oct 2014 15:19:57 +0200 Subject: hub: Add query for last-update-id for given UUID to store, web. --- src/hub/src/spreadspace.org/sfive/s5srvWeb.go | 12 ++++++++++++ src/hub/src/spreadspace.org/sfive/s5store.go | 12 ++++++++++++ 2 files changed, 24 insertions(+) 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" } -- cgit v1.2.3