aboutsummaryrefslogtreecommitdiff
path: root/lib/handlers/posts.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlers/posts.js')
-rw-r--r--lib/handlers/posts.js14
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);
};
}