summaryrefslogtreecommitdiff
path: root/system/api/analytics/init.go
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2016-12-13 09:13:45 -0800
committerSteve Manuel <nilslice@gmail.com>2016-12-13 09:13:45 -0800
commitc0a2d56bb102b52f06a87851fc8a7164ef306358 (patch)
treef9a5cde43a3f818c4472f9e07280ffd08fb8b09b /system/api/analytics/init.go
parenta92afa283947f1bbf9b12525982af74f6ce1f469 (diff)
testing memory cache of current metrics rather than lookup in db
Diffstat (limited to 'system/api/analytics/init.go')
-rw-r--r--system/api/analytics/init.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/system/api/analytics/init.go b/system/api/analytics/init.go
index 9942dc2..fc7ecea 100644
--- a/system/api/analytics/init.go
+++ b/system/api/analytics/init.go
@@ -161,6 +161,7 @@ func ChartData() (map[string]interface{}, error) {
// get api request analytics and metrics from db
var requests = []apiRequest{}
var metrics = [RANGE]apiMetric{}
+ currentMetrics := make(map[string]struct{})
err := store.Update(func(tx *bolt.Tx) error {
m := tx.Bucket([]byte("__metrics"))
@@ -174,6 +175,9 @@ func ChartData() (map[string]interface{}, error) {
return nil
}
+ // add metric to currentMetrics map
+ currentMetrics[metric.Date] = struct{}{}
+
// if the metric date is in current date range, insert it into
// metrics array at the position of the date in dates array
for i := range dates {
@@ -199,7 +203,8 @@ func ChartData() (map[string]interface{}, error) {
// append request to requests for analysis if its timestamp is today
// and its day is not already in cache
d := time.Unix(r.Timestamp/1000, 0)
- if !d.Before(today) && m.Get([]byte(d.Format("01/02"))) == nil {
+ _, inCache := currentMetrics[d.Format("01/02")]
+ if !d.Before(today) && !inCache {
requests = append(requests, r)
}