This commit is contained in:
Jeff McAffer 2016-11-12 09:46:00 -08:00
Родитель 6c01a9f49d
Коммит 7b903d5ca6
2 изменённых файлов: 15 добавлений и 9 удалений

Просмотреть файл

@ -25,15 +25,20 @@ class EventFinder {
}
getNewEvents(eventSource) {
const self = this;
return this.requestor.getAll(eventSource).then(self._findNew.bind(self));
return this.requestor.getAll(eventSource).then(this._findNew.bind(this));
}
// Find the events for which we do NOT have a document.
_findNew(events) {
const limit = qlimit(10);
return Q.all(events.filter(limit(event => {
return !this.eventStore.etag('event', event.url, (err, tag));
})));
const self = this;
return Q.all(events.map(qlimit(10)(event => {
return self.eventStore.etag('event', event.url).then(etag => {
return etag ? null : event;
});
}))).then(events => {
return events.filter(event =>event);
});
}
}
module.exports = EventFinder;

Просмотреть файл

@ -18,6 +18,7 @@ describe('Event Finder', () => {
expect(found[0].url).to.be.equal('http://test1');
});
});
it('will not find any documents', () => {
const events = [
[{ url: 'http://test1' }, { url: 'http://test2' }]
@ -29,6 +30,7 @@ describe('Event Finder', () => {
expect(found.length).to.be.equal(0);
});
});
it('will stop not finding at first found document', () => {
const events = [
[{ url: 'http://test1' }, { url: 'http://test2' }, { url: 'http://test3' }]
@ -64,10 +66,9 @@ function createStore(documents) {
extend(collection, document);
return collection;
}, {});
result.etag = (type, url, callback) => {
result.etag = (type, url) => {
let result = hash[url];
result = result ? result.etag : null;
return callback ? callback(null, result) : Q(result);
return Q(result ? result.etag : null);
};
return result;
}