Minor cleanup in SearchPager

This commit is contained in:
Patrick Mooney 2014-07-25 13:21:02 -05:00
parent d665378c0e
commit b555463a90
2 changed files with 11 additions and 6 deletions

View File

@ -810,7 +810,7 @@ Client.prototype.search = function search(base,
size = pageOpts.pageSize; size = pageOpts.pageSize;
} else if (options.sizeLimit > 1) { } else if (options.sizeLimit > 1) {
// According to the RFC, servers should ignore the paging control if // 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. // to stay under that figure when assigning a default value.
size = options.sizeLimit - 1; size = options.sizeLimit - 1;
} }

View File

@ -81,16 +81,18 @@ SearchPager.prototype._onEntry = function _onEntry(entry) {
SearchPager.prototype._onEnd = function _onEnd(res) { SearchPager.prototype._onEnd = function _onEnd(res) {
var self = this; var self = this;
var cookie = null; var cookie = null;
var nullFunc = function () { };
res.controls.forEach(function (control) { res.controls.forEach(function (control) {
if (control.type === PagedControl.OID) { if (control.type === PagedControl.OID) {
cookie = control.value.cookie; cookie = control.value.cookie;
} }
}); });
// Pass a noop callback by default for page events
var nullCb = function () { };
if (cookie === null) { if (cookie === null) {
// paged search not supported // paged search not supported
this.finished = true; this.finished = true;
this.emit('page', res, nullFunc); this.emit('page', res, nullCb);
var err = new Error('missing paged control'); var err = new Error('missing paged control');
err.name = 'PagedError'; err.name = 'PagedError';
if (this.listeners('pageError') > 0) { if (this.listeners('pageError') > 0) {
@ -104,10 +106,13 @@ SearchPager.prototype._onEnd = function _onEnd(res) {
this.emit('error', err); this.emit('error', err);
// No end event possible per explaination above. // No end event possible per explaination above.
} }
} else if (cookie.length === 0) { return;
}
if (cookie.length === 0) {
// end of paged results // end of paged results
this.finished = true; this.finished = true;
this.emit('page', nullFunc); this.emit('page', nullCb);
this.emit('end', res); this.emit('end', res);
} else { } else {
if (this.pagePause) { if (this.pagePause) {
@ -122,7 +127,7 @@ SearchPager.prototype._onEnd = function _onEnd(res) {
} }
}); });
} else { } else {
this.emit('page', res, nullFunc); this.emit('page', res, nullCb);
this._nextPage(cookie); this._nextPage(cookie);
} }
} }