diff --git a/lib/client.js b/lib/client.js index 0c0240b..3963ab8 100644 --- a/lib/client.js +++ b/lib/client.js @@ -18,9 +18,10 @@ SearchSource = function SearchSource(source, fields, options) { SearchSource.prototype._loadData = function(query, options) { var self = this; var version = 0; - if(this._canUseHistory(query)) { - this._updateStore(this.history[query].data); - this.metaData.set(this.history[query].metadata); + var historyKey = query + EJSON.stringify(options); + if(this._canUseHistory(historyKey)) { + this._updateStore(this.history[historyKey].data); + this.metaData.set(this.history[historyKey].metadata); self._storeDep.changed(); } else { this.status.set({loading: true}); @@ -43,7 +44,7 @@ SearchSource.prototype._loadData = function(query, options) { } if(self.options.keepHistory) { - self.history[query] = {data: data, loaded: new Date(), metadata: metadata}; + self.history[historyKey] = {data: data, loaded: new Date(), metadata: metadata}; } if(version > self._loadedVersion) { @@ -60,8 +61,8 @@ SearchSource.prototype._loadData = function(query, options) { } }; -SearchSource.prototype._canUseHistory = function(query) { - var historyItem = this.history[query]; +SearchSource.prototype._canUseHistory = function(historyKey) { + var historyItem = this.history[historyKey]; if(this.options.keepHistory && historyItem) { var diff = Date.now() - historyItem.loaded.getTime(); return diff < this.options.keepHistory; @@ -81,7 +82,7 @@ SearchSource.prototype._updateStore = function(data) { // Remove items in client DB that we no longer need var currentIdMappings = {}; - _.each(currentIds, function(currentId) { + _.each(currentIds, function(currentId) { // to support Object Ids var str = (currentId._str)? currentId._str : currentId; currentIdMappings[str] = true; @@ -138,7 +139,7 @@ SearchSource.prototype.getData = function(options, getCursor) { if(options.docTransform) { return options.docTransform(doc); } - + return doc; }