Commit f0952377664cc671d536cff9d13918e967964e04
Attempt to fix pagination issues
- Filter messages before passing them to paginate function, so that the paginate function picks the correct one as the last one. - Remove obsolete lt/gt hack - Try to handle sortByTimestamp for /mentions TODO: avoid calling filterMsg multiple times per messagecel committed on 5/16/2018, 6:27:02 PM
Parent: df3ff8760da8e958fcd40e187fbc0dc63e47a5d0
Files changed
lib/app.js | changed |
lib/serve.js | changed |
lib/app.js | |||
---|---|---|---|
@@ -389,17 +389,15 @@ | |||
389 | 389 … | } | |
390 | 390 … | ||
391 | 391 … | App.prototype.createFeedStream = function (opts) { | |
392 | 392 … | // work around opts.gt being treated as opts.gte sometimes | |
393 | - var limit = Number(opts.limit) | ||
394 | - if (opts.gt && limit && !opts.reverse) return pull( | ||
395 | - this.sbot.createFeedStream(u.mergeOpts(opts, {limit: opts.limit + 1})), | ||
393 … | + return pull( | ||
394 … | + this.sbot.createFeedStream(opts), | ||
396 | 395 … | pull.filter(function (msg) { | |
397 | - return msg && msg.value.timestamp !== opts.gt | ||
398 | - }), | ||
399 | - limit && pull.take(limit) | ||
396 … | + var ts = msg && msg.value && msg.value.timestamp | ||
397 … | + return typeof ts === 'number' && ts !== opts.gt && ts !== opts.lt | ||
398 … | + }) | ||
400 | 399 … | ) | |
401 | - return this.sbot.createFeedStream(opts) | ||
402 | 400 … | } | |
403 | 401 … | ||
404 | 402 … | var stateVals = { | |
405 | 403 … | connected: 3, | |
@@ -592,27 +590,40 @@ | |||
592 | 590 … | var index | |
593 | 591 … | if (plugin === this.sbot.backlinks) { | |
594 | 592 … | var c = filter && filter.value && filter.value.content | |
595 | 593 … | var filteringByType = c && c.type | |
596 | - if (!filteringByType) index = 'DTS' | ||
594 … | + if (opts.sortByTimestamp) index = 'DTA' | ||
595 … | + else if (filteringByType) index = 'DTS' | ||
597 | 596 … | } | |
598 | - // work around flumeview-query not supporting $lt/$gt. | ||
599 | - // %FCIv0D7JQyERznC18p8Dc1KtN6SLeJAl1sR5DAIr/Ek=.sha256 | ||
597 … | + var filterOpts = { | ||
598 … | + $gt: opts.gt, | ||
599 … | + $lt: opts.lt, | ||
600 … | + } | ||
601 … | + return plugin.read({ | ||
602 … | + index: index, | ||
603 … | + reverse: opts.reverse, | ||
604 … | + limit: limit || undefined, | ||
605 … | + query: [{$filter: u.mergeOpts(filter, opts.sortByTimestamp ? { | ||
606 … | + value: { | ||
607 … | + timestamp: filterOpts | ||
608 … | + } | ||
609 … | + } : { | ||
610 … | + timestamp: filterOpts | ||
611 … | + })}] | ||
612 … | + }) | ||
613 … | +} | ||
614 … | + | ||
615 … | +App.prototype.filterMessages = function (opts) { | ||
616 … | + var self = this | ||
617 … | + var limit = Number(opts.limit) | ||
600 | 618 … | return pull( | |
601 | - plugin.read({ | ||
602 | - index: index, | ||
603 | - reverse: opts.reverse, | ||
604 | - limit: limit ? (limit + 1) : undefined, | ||
605 | - query: [{$filter: u.mergeOpts(filter, { | ||
606 | - timestamp: { | ||
607 | - $gte: opts.gt, | ||
608 | - $lte: opts.lt, | ||
609 | - } | ||
610 | - })}] | ||
611 | - }), | ||
612 | - pull.filter(function (msg) { | ||
613 | - return msg && msg.timestamp !== opts.lt && msg.timestamp !== opts.gt | ||
614 | - }), | ||
619 … | + paramap(function (msg, cb) { | ||
620 … | + self.filterMsg(msg, opts, function (err, show) { | ||
621 … | + if (err) return cb(err) | ||
622 … | + cb(null, show ? msg : null) | ||
623 … | + }) | ||
624 … | + }, 4), | ||
625 … | + pull.filter(Boolean), | ||
615 | 626 … | limit && pull.take(limit) | |
616 | 627 … | ) | |
617 | 628 … | } | |
618 | 629 … |
lib/serve.js | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 102716 bytes New file size: 102896 bytes |
Built with git-ssb-web