Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -138,7 +139,7 @@ SearchSource.prototype.getData = function(options, getCursor) {
if(options.docTransform) {
return options.docTransform(doc);
}

return doc;
}

Expand Down