Skip to content

Commit d43ac8e

Browse files
committed
Merge pull request #34 from kueblboe/master
Consider options for cached history.
2 parents d740bb6 + c504027 commit d43ac8e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/client.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ SearchSource = function SearchSource(source, fields, options) {
1818
SearchSource.prototype._loadData = function(query, options) {
1919
var self = this;
2020
var version = 0;
21-
if(this._canUseHistory(query)) {
22-
this._updateStore(this.history[query].data);
23-
this.metaData.set(this.history[query].metadata);
21+
var historyKey = query + EJSON.stringify(options);
22+
if(this._canUseHistory(historyKey)) {
23+
this._updateStore(this.history[historyKey].data);
24+
this.metaData.set(this.history[historyKey].metadata);
2425
self._storeDep.changed();
2526
} else {
2627
this.status.set({loading: true});
@@ -43,7 +44,7 @@ SearchSource.prototype._loadData = function(query, options) {
4344
}
4445

4546
if(self.options.keepHistory) {
46-
self.history[query] = {data: data, loaded: new Date(), metadata: metadata};
47+
self.history[historyKey] = {data: data, loaded: new Date(), metadata: metadata};
4748
}
4849

4950
if(version > self._loadedVersion) {
@@ -60,8 +61,8 @@ SearchSource.prototype._loadData = function(query, options) {
6061
}
6162
};
6263

63-
SearchSource.prototype._canUseHistory = function(query) {
64-
var historyItem = this.history[query];
64+
SearchSource.prototype._canUseHistory = function(historyKey) {
65+
var historyItem = this.history[historyKey];
6566
if(this.options.keepHistory && historyItem) {
6667
var diff = Date.now() - historyItem.loaded.getTime();
6768
return diff < this.options.keepHistory;
@@ -81,7 +82,7 @@ SearchSource.prototype._updateStore = function(data) {
8182

8283
// Remove items in client DB that we no longer need
8384
var currentIdMappings = {};
84-
_.each(currentIds, function(currentId) {
85+
_.each(currentIds, function(currentId) {
8586
// to support Object Ids
8687
var str = (currentId._str)? currentId._str : currentId;
8788
currentIdMappings[str] = true;
@@ -138,7 +139,7 @@ SearchSource.prototype.getData = function(options, getCursor) {
138139
if(options.docTransform) {
139140
return options.docTransform(doc);
140141
}
141-
142+
142143
return doc;
143144
}
144145

0 commit comments

Comments
 (0)