Skip to content

Commit bde39e2

Browse files
committed
remove fetchAllDocuments method
1 parent ec13b7f commit bde39e2

File tree

4 files changed

+40
-151
lines changed

4 files changed

+40
-151
lines changed

src/Collection.js

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -306,61 +306,6 @@ Collection.prototype.fetchDocument = function (documentId, options, cb) {
306306
});
307307
};
308308

309-
/**
310-
* Retrieves all documents stored in this data collection
311-
*
312-
* @param {object} [options] - Optional parameters
313-
* @param {responseCallback} cb - Handles the query response
314-
*/
315-
Collection.prototype.fetchAllDocuments = function (options, cb) {
316-
var
317-
warnEmitted = false,
318-
documents = [],
319-
filters = {};
320-
321-
if (!cb && typeof options === 'function') {
322-
cb = options;
323-
options = {};
324-
}
325-
326-
// copying pagination options to the search filter
327-
if (!options) {
328-
options = {};
329-
}
330-
331-
if (!options.from) {
332-
options.from = 0;
333-
}
334-
335-
if (!options.size) {
336-
options.size = 1000;
337-
}
338-
339-
this.kuzzle.callbackRequired('Collection.fetchAllDocuments', cb);
340-
341-
this.search(filters, options, function fetchNextDocuments (error, searchResult) {
342-
if (error) {
343-
return cb(error);
344-
}
345-
346-
if (searchResult instanceof KuzzleSearchResult) {
347-
if (searchResult.total > 10000 && !warnEmitted) {
348-
warnEmitted = true;
349-
console.warn('Collection.fetchAllDocuments may return extremely large amounts of documents, which may cause performance issues. Unless you know what you are doing, consider using Collection.search or Collection.scroll instead'); // eslint-disable-line no-console
350-
}
351-
352-
searchResult.documents.forEach(function(document) {
353-
documents.push(document);
354-
});
355-
searchResult.fetchNext(fetchNextDocuments);
356-
}
357-
else {
358-
cb(null, documents);
359-
}
360-
});
361-
};
362-
363-
364309
/**
365310
* Instantiates a CollectionMapping object containing the current mapping of this collection.
366311
*

test/Collection/constructor.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ describe('Collection constructor', function () {
4545
should.exist(collection.deleteDocumentPromise);
4646
should.exist(collection.documentExistsPromise);
4747
should.exist(collection.fetchDocumentPromise);
48-
should.exist(collection.fetchAllDocumentsPromise);
4948
should.exist(collection.getMappingPromise);
5049
should.exist(collection.mCreateDocumentPromise);
5150
should.exist(collection.mCreateOrReplaceDocumentPromise);

test/Collection/methods.test.js

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -594,71 +594,6 @@ describe('Collection methods', function () {
594594
});
595595
});
596596

597-
describe('#fetchAllDocuments', function () {
598-
beforeEach(function () {
599-
collection.search = sinon.stub();
600-
expectedQuery = {
601-
index: 'bar',
602-
collection: 'foo',
603-
action: 'get',
604-
controller: 'document'
605-
};
606-
});
607-
608-
it('should forward the query to the search method', function () {
609-
var options = { queuable: false };
610-
611-
collection.fetchAllDocuments(options, sinon.stub());
612-
should(collection.search).be.calledOnce();
613-
should(collection.search).be.calledWith({}, options, sinon.match.func);
614-
});
615-
616-
it('should raise an error if no callback is provided', function () {
617-
should(function () { collection.fetchAllDocuments(); }).throw(Error);
618-
should(function () { collection.fetchAllDocuments({}); }).throw(Error);
619-
should(collection.search).not.be.called();
620-
});
621-
622-
it('should handle the callback argument correctly', function () {
623-
var
624-
cb1 = sinon.stub(),
625-
cb2 = sinon.stub();
626-
627-
collection.fetchAllDocuments(cb1);
628-
collection.fetchAllDocuments({}, cb2);
629-
630-
should(collection.search).be.calledTwice();
631-
632-
collection.search.yield(null, 'foobar');
633-
should(cb1).be.calledOnce();
634-
should(cb2).be.calledOnce();
635-
});
636-
637-
it('should handle the from and size options', function () {
638-
collection.fetchAllDocuments({from: 123, size: 456}, sinon.stub());
639-
should(collection.search).be.calledOnce();
640-
should(collection.search).be.calledWith({}, {from: 123, size: 456}, sinon.match.func);
641-
});
642-
643-
it('should handle the scroll options', function () {
644-
collection.fetchAllDocuments({scroll: '30s'}, function () {});
645-
should(collection.search).be.calledOnce();
646-
should(collection.search).be.calledWith({}, {from: 0, size: 1000, scroll: '30s'}, sinon.match.func);
647-
});
648-
649-
it('should transfer error if any', function (done) {
650-
this.timeout(50);
651-
652-
collection.fetchAllDocuments(function (er) {
653-
should(er).be.an.instanceOf(Error);
654-
should(er.message).be.exactly('foobar');
655-
done();
656-
});
657-
658-
collection.search.yield(new Error('foobar'));
659-
});
660-
});
661-
662597
describe('#getMapping', function () {
663598
beforeEach(function () {
664599
result = { result: {'bar': { mappings: { foo: { properties: {}}}} }};

test/kuzzle/offlineQueue.test.js

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ var
66

77
describe('Offline queue management', function () {
88
var
9+
clock,
910
now,
10-
kuzzle;
11+
kuzzle,
12+
reset;
1113

1214
beforeEach(function () {
1315
var pastTime = 60050;
@@ -16,12 +18,25 @@ describe('Offline queue management', function () {
1618

1719
// queuing a bunch of 7 requests from 1min ago to right now, 10s apart
1820
now = Date.now();
21+
clock = sinon.useFakeTimers(now);
22+
23+
reset = Kuzzle.__set__({
24+
setTimeout: clock.setTimeout,
25+
setInterval: clock.setInterval,
26+
clearTimeout: clock.clearTimeout,
27+
clearInterval: clock.clearInterval
28+
});
29+
1930
while (pastTime >= 0) {
2031
kuzzle.offlineQueue.push({ts: now - pastTime, query: {requestId: pastTime, action: 'foo', controller: 'bar'}, cb: function () {}});
2132
pastTime -= 10000;
2233
}
2334
});
2435

36+
afterEach(() => {
37+
clock.restore();
38+
});
39+
2540
describe('#cleanQueue', function () {
2641
var
2742
cleanQueue = Kuzzle.__get__('cleanQueue');
@@ -92,31 +107,28 @@ describe('Offline queue management', function () {
92107
emitRequestStub.reset();
93108
});
94109

95-
it('should play all queued requests', function (done) {
110+
it('should play all queued requests', function () {
96111
var
97112
numRequests = kuzzle.offlineQueue.length,
98113
eventStub = sinon.stub();
99114

100-
this.timeout(200);
101115
kuzzle.addListener('offlineQueuePop', eventStub);
102116
dequeue.call(kuzzle);
103117

104-
setTimeout(function () {
105-
should(emitRequestStub.callCount).be.exactly(numRequests);
106-
should(kuzzle.offlineQueue).be.an.Array();
107-
should(kuzzle.offlineQueue.length).be.exactly(0);
108-
should(kuzzle.queuing).be.false();
109-
should(eventStub.callCount).be.exactly(numRequests);
110-
done();
111-
}, numRequests * kuzzle.replayInterval + 50);
118+
clock.tick(numRequests * kuzzle.replayInterval + 50);
119+
120+
should(emitRequestStub.callCount).be.exactly(numRequests);
121+
should(kuzzle.offlineQueue).be.an.Array();
122+
should(kuzzle.offlineQueue.length).be.exactly(0);
123+
should(kuzzle.queuing).be.false();
124+
should(eventStub.callCount).be.exactly(numRequests);
112125
});
113126

114-
it('should also load the queue provided by the offlineQueueLoader property', function (done) {
127+
it('should also load the queue provided by the offlineQueueLoader property', function () {
115128
var
116129
numRequests = kuzzle.offlineQueue.length,
117130
eventStub = sinon.stub();
118131

119-
this.timeout(200);
120132
kuzzle.offlineQueueLoader = function () {
121133
return [
122134
{query: {requestId: 'foo', action: 'action', controller: 'controller'}},
@@ -126,17 +138,16 @@ describe('Offline queue management', function () {
126138
kuzzle.addListener('offlineQueuePop', eventStub);
127139
dequeue.call(kuzzle);
128140

129-
setTimeout(function () {
130-
should(emitRequestStub.callCount).be.exactly(numRequests + 2);
131-
should(kuzzle.offlineQueue).be.an.Array();
132-
should(kuzzle.offlineQueue.length).be.exactly(0);
133-
should(kuzzle.queuing).be.false();
134-
should(eventStub.callCount).be.exactly(numRequests + 2);
135-
done();
136-
}, (numRequests +2) * kuzzle.replayInterval + 50);
141+
clock.tick((numRequests + 2) * kuzzle.replayInterval + 50);
142+
143+
should(emitRequestStub.callCount).be.exactly(numRequests + 2);
144+
should(kuzzle.offlineQueue).be.an.Array();
145+
should(kuzzle.offlineQueue.length).be.exactly(0);
146+
should(kuzzle.queuing).be.false();
147+
should(eventStub.callCount).be.exactly(numRequests + 2);
137148
});
138149

139-
it('should filter duplicates from the offlineQueueLoader and the cached queue ', function (done) {
150+
it('should filter duplicates from the offlineQueueLoader and the cached queue ', () => {
140151
var
141152
numRequests = kuzzle.offlineQueue.length,
142153
eventStub = sinon.stub();
@@ -151,14 +162,13 @@ describe('Offline queue management', function () {
151162
kuzzle.addListener('offlineQueuePop', eventStub);
152163
dequeue.call(kuzzle);
153164

154-
setTimeout(function () {
155-
should(emitRequestStub.callCount).be.exactly(numRequests + 1);
156-
should(kuzzle.offlineQueue).be.an.Array();
157-
should(kuzzle.offlineQueue.length).be.exactly(0);
158-
should(kuzzle.queuing).be.false();
159-
should(eventStub.callCount).be.exactly(numRequests + 1);
160-
done();
161-
}, (numRequests + 1) * kuzzle.replayInterval + 50);
165+
clock.tick((numRequests + 1) * kuzzle.replayInterval + 50);
166+
167+
should(emitRequestStub.callCount).be.exactly(numRequests + 1);
168+
should(kuzzle.offlineQueue).be.an.Array();
169+
should(kuzzle.offlineQueue.length).be.exactly(0);
170+
should(kuzzle.queuing).be.false();
171+
should(eventStub.callCount).be.exactly(numRequests + 1);
162172
});
163173

164174
it('should throw on erroneous queries returned by the offlineQueueLoader property', function () {

0 commit comments

Comments
 (0)