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