diff options
| author | Rubén Beltrán del Río <ben@nsovocal.com> | 2017-01-31 00:49:26 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-31 00:49:26 -0600 |
| commit | 9b1f50fefe021578113b8f5935084fe4fed110b2 (patch) | |
| tree | 98805583b7c5041f16b195de823c5524f4de7672 /lib/handlers/posts.js | |
| parent | a6ccda0fbc4df683f9568d85eb22b21684d2a0bd (diff) | |
Add Comments (#4)
* Preserve whitespace in posts
* Create comments handler
* Use comments handler
* Update paw
* Add comment components
* Style comments
* Remove unnecessary code from app
* Fix linter warning
* Add key to handle children (thx @javierbyte)
* Add toggling to the form
* Return all keys always
* Correct missing semicolons
* Restore redirect
* Render posts conditionally
* Set poll time to 1s
* Set post frequency to 2s
* Add polling to comments
* Correct typo in error logging
* Clear intervals and reduce polling
* Stops polling if it's being destroyed
* Update changelog
Diffstat (limited to 'lib/handlers/posts.js')
| -rw-r--r-- | lib/handlers/posts.js | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/handlers/posts.js b/lib/handlers/posts.js index 425fb5e..b5e4f0e 100644 --- a/lib/handlers/posts.js +++ b/lib/handlers/posts.js @@ -60,16 +60,18 @@ module.exports = internals.PostsHandler = class PostsHandler { const scan = Pify(self._redis.scan.bind(self._redis)); const hgetall = Pify(self._redis.hgetall.bind(self._redis)); - const cursor = parseInt(this.request.query.cursor) || 0; - const [nextCursor, keys] = yield scan(cursor, 'MATCH', `${internals.kPostsPrefix}:*`); + let keys = []; + let nextCursor = 0; + let currentKeys = null; - if (nextCursor > 0) { - this.append('Link', `<${this.request.origin}${this.request.path}?cursor=${nextCursor}>; rel="next"`); - } + do { + [nextCursor, currentKeys] = yield scan(nextCursor || 0, 'MATCH', `${internals.kPostsPrefix}:*`); + keys = keys.concat(currentKeys); + } while (nextCursor > 0); const posts = yield keys.map((key) => hgetall(key)); - this.body = posts; + this.body = posts.sort((a, b) => b.timestamp - a.timestamp); }; } |