Minor cleanup in SearchPager
This commit is contained in:
parent
d665378c0e
commit
b555463a90
|
@ -810,7 +810,7 @@ Client.prototype.search = function search(base,
|
|||
size = pageOpts.pageSize;
|
||||
} else if (options.sizeLimit > 1) {
|
||||
// According to the RFC, servers should ignore the paging control if
|
||||
// pageSize >= sizelimit. Some will still send results, but it's safer
|
||||
// pageSize >= sizelimit. Some might still send results, but it's safer
|
||||
// to stay under that figure when assigning a default value.
|
||||
size = options.sizeLimit - 1;
|
||||
}
|
||||
|
|
|
@ -81,16 +81,18 @@ SearchPager.prototype._onEntry = function _onEntry(entry) {
|
|||
SearchPager.prototype._onEnd = function _onEnd(res) {
|
||||
var self = this;
|
||||
var cookie = null;
|
||||
var nullFunc = function () { };
|
||||
res.controls.forEach(function (control) {
|
||||
if (control.type === PagedControl.OID) {
|
||||
cookie = control.value.cookie;
|
||||
}
|
||||
});
|
||||
// Pass a noop callback by default for page events
|
||||
var nullCb = function () { };
|
||||
|
||||
if (cookie === null) {
|
||||
// paged search not supported
|
||||
this.finished = true;
|
||||
this.emit('page', res, nullFunc);
|
||||
this.emit('page', res, nullCb);
|
||||
var err = new Error('missing paged control');
|
||||
err.name = 'PagedError';
|
||||
if (this.listeners('pageError') > 0) {
|
||||
|
@ -104,10 +106,13 @@ SearchPager.prototype._onEnd = function _onEnd(res) {
|
|||
this.emit('error', err);
|
||||
// No end event possible per explaination above.
|
||||
}
|
||||
} else if (cookie.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cookie.length === 0) {
|
||||
// end of paged results
|
||||
this.finished = true;
|
||||
this.emit('page', nullFunc);
|
||||
this.emit('page', nullCb);
|
||||
this.emit('end', res);
|
||||
} else {
|
||||
if (this.pagePause) {
|
||||
|
@ -122,7 +127,7 @@ SearchPager.prototype._onEnd = function _onEnd(res) {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
this.emit('page', res, nullFunc);
|
||||
this.emit('page', res, nullCb);
|
||||
this._nextPage(cookie);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue