From 6ad7d0bfaba07cf1a4823c4878bb80a3db2aabe2 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Fri, 12 Aug 2016 10:02:57 -0600 Subject: [PATCH] fix count() cache retrieval --- cache.go | 3 ++- fragment.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cache.go b/cache.go index 03e02d15f..2ff5f60ce 100644 --- a/cache.go +++ b/cache.go @@ -51,7 +51,8 @@ func (c *LRUCache) Add(bitmapID, n uint64) { // Get returns a bitmap with a given id. func (c *LRUCache) Get(bitmapID uint64) uint64 { n, _ := c.cache.Get(bitmapID) - return n.(uint64) + nn, _ := n.(uint64) + return nn } // Len returns the number of items in the cache. diff --git a/fragment.go b/fragment.go index c1ded3c1c..6d32bca9d 100644 --- a/fragment.go +++ b/fragment.go @@ -527,6 +527,16 @@ func (f *Fragment) topBitmapPairs(bitmapIDs []uint64) []BitmapPair { // Otherwise retrieve specific bitmaps. pairs := make([]BitmapPair, len(bitmapIDs)) for i, bitmapID := range bitmapIDs { + // Look up cache first, if available. + if n := f.cache.Get(bitmapID); n > 0 { + pairs[i] = BitmapPair{ + ID: bitmapID, + Count: n, + } + continue + } + + // Otherwise load from storage. pairs[i] = BitmapPair{ ID: bitmapID, Count: f.Bitmap(bitmapID).Count(),