From c648f118d9f332648376eba1b8293ad4278e333c Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Fri, 12 Apr 2019 14:30:39 +0200 Subject: [PATCH] cursor-based pagination for activities api. #238 --- app/models/concerns/indexable.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index eadb1b2b3..d1ddc9583 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -108,6 +108,10 @@ def query(query, options={}) from = 0 search_after = [options.dig(:page, :cursor)] sort = [{ _id: { order: 'asc' }}] + elsif self.name == "Activity" && options.dig(:page, :cursor).present? + from = 0 + search_after = [options.dig(:page, :cursor)] + sort = [{ created: { order: 'asc' }}] else from = (options.dig(:page, :number) - 1) * options.dig(:page, :size) search_after = nil