From 7c24ff9eb9a561b7dac998a09d9a489a16e8bd2b Mon Sep 17 00:00:00 2001 From: Adam Eijdenberg Date: Fri, 8 Jun 2018 09:15:19 +1000 Subject: [PATCH 1/2] Byte slices are only valid WITHIN the bolt transactation. See "Caveats" in bolt doc: https://godoc.org/github.com/boltdb/bolt#hdr-Caveats This commit refactors to ensure that the value slice is not used after the transaction. --- caching/caching_boltdb.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/caching/caching_boltdb.go b/caching/caching_boltdb.go index 08f8d26..3191f2a 100644 --- a/caching/caching_boltdb.go +++ b/caching/caching_boltdb.go @@ -167,26 +167,21 @@ func (c *CachingBolt) getAppFromCache(appGuid string) (*App, error) { } func (c *CachingBolt) getAllAppsFromBoltDB() (map[string]*App, error) { - var allData [][]byte - c.appdb.View(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte(APP_BUCKET)) - b.ForEach(func(guid []byte, v []byte) error { - allData = append(allData, v) + apps := make(map[string]*App) + err := c.appdb.View(func(tx *bolt.Tx) error { + return tx.Bucket([]byte(APP_BUCKET)).ForEach(func(guid []byte, v []byte) error { + var app App + err := json.Unmarshal(v, &app) + if err != nil { + return err + } + apps[app.Guid] = &app return nil }) - return nil }) - - apps := make(map[string]*App, len(allData)) - for i := range allData { - var app App - err := json.Unmarshal(allData[i], &app) - if err != nil { - return nil, err - } - apps[app.Guid] = &app + if err != nil { + return nil, err } - return apps, nil } From 56f6998c5dce907f7fc33c81953694045e091efb Mon Sep 17 00:00:00 2001 From: Etourneau Gwenn Date: Fri, 8 Jun 2018 14:38:37 +0900 Subject: [PATCH 2/2] Removing noisy logs --- eventRouting/event_filter.go | 1 + 1 file changed, 1 insertion(+) diff --git a/eventRouting/event_filter.go b/eventRouting/event_filter.go index bf12e45..36f8a80 100644 --- a/eventRouting/event_filter.go +++ b/eventRouting/event_filter.go @@ -12,6 +12,7 @@ type EventFilter func(*fevents.Event) bool //HasIgnoreField Filter out the event has ignored app filed func HasIgnoreField(event *fevents.Event) bool { ignored, hasIgnoredField := event.Fields["cf_ignored_app"] + delete(event.Fields, "cf_ignored_app") return ignored == true && hasIgnoredField }