From 1bd718a5f8a5268ca580dded82a6c5fc5b8480dd Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Fri, 8 May 2015 17:35:58 -0300 Subject: [PATCH] Ranking pagination --- lib/proposals_discussion_plugin/api.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/proposals_discussion_plugin/api.rb b/lib/proposals_discussion_plugin/api.rb index 1eab207..89954a4 100644 --- a/lib/proposals_discussion_plugin/api.rb +++ b/lib/proposals_discussion_plugin/api.rb @@ -2,9 +2,10 @@ class ProposalsDiscussionPlugin::API < Grape::API resource :proposals_discussion_plugin do + paginate per_page: 10, max_per_page: 20 get ':id/ranking' do article = find_article(environment.articles, params[:id]) - Rails.cache.fetch("#{article.cache_key}/proposals_ranking", expires_in: 10.minutes) do + ranking = Rails.cache.fetch("#{article.cache_key}/proposals_ranking", expires_in: 10.minutes) do max_hits = article.proposals.maximum(:hits) min_hits = article.proposals.minimum(:hits) @@ -17,6 +18,8 @@ class ProposalsDiscussionPlugin::API < Grape::API proposals = proposals.sort_by { |p| p[:effective_support] }.reverse {:proposals => proposals, :updated_at => DateTime.now} end + ranking[:proposals] = paginate ranking[:proposals] + ranking end end -- libgit2 0.21.2