summaryrefslogtreecommitdiff
path: root/system/api/analytics/init.go
diff options
context:
space:
mode:
authorSteve <nilslice@gmail.com>2016-11-02 02:27:29 -0700
committerGitHub <noreply@github.com>2016-11-02 02:27:29 -0700
commitbd27ac1f0dbff856ca3e96d1df636f3b02d61522 (patch)
treebe9b5b86b7da34a150e228a817335d368b8705ca /system/api/analytics/init.go
parentac647e2f77d05cc015a369832c2d428ec1cd6567 (diff)
parent759506ca799c443402fed9c6413a8b49406e197f (diff)
Merge pull request #12 from bosssauce/ponzu-dev
[core] More efficient DB queries
Diffstat (limited to 'system/api/analytics/init.go')
-rw-r--r--system/api/analytics/init.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/system/api/analytics/init.go b/system/api/analytics/init.go
index c351bed..3af1407 100644
--- a/system/api/analytics/init.go
+++ b/system/api/analytics/init.go
@@ -15,6 +15,7 @@ import (
type apiRequest struct {
URL string `json:"url"`
Method string `json:"http_method"`
+ Origin string `json:"origin"`
RemoteAddr string `json:"ip_address"`
Timestamp int64 `json:"timestamp"`
External bool `json:"external"`
@@ -32,6 +33,7 @@ func Record(req *http.Request) {
r := apiRequest{
URL: req.URL.String(),
Method: req.Method,
+ Origin: req.Header.Get("Origin"),
RemoteAddr: req.RemoteAddr,
Timestamp: time.Now().Unix() * 1000,
External: external,
@@ -39,7 +41,6 @@ func Record(req *http.Request) {
// put r on buffered recordChan to take advantage of batch insertion in DB
recordChan <- r
-
}
// Close exports the abillity to close our db file. Should be called with defer
@@ -64,10 +65,6 @@ func Init() {
go serve()
- err = store.Update(func(tx *bolt.Tx) error {
-
- return nil
- })
if err != nil {
log.Fatalln(err)
}
@@ -93,6 +90,11 @@ func serve() {
reqs = append(reqs, <-recordChan)
}
+ err := batchInsert(reqs)
+ if err != nil {
+ log.Println(err)
+ }
+
case <-pruneDBTimer.C:
default: