From c7e2ea0ddcab5ac082c94b4d83faf9ef759bf16d Mon Sep 17 00:00:00 2001 From: Duane Johnson Date: Fri, 5 Dec 2014 11:15:58 -0700 Subject: [PATCH] add per_page for server middleware, paginate wating queue --- lib/qless/server.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/qless/server.rb b/lib/qless/server.rb index 1614ea37..68bc1214 100755 --- a/lib/qless/server.rb +++ b/lib/qless/server.rb @@ -65,10 +65,17 @@ def current_page end end - PAGE_SIZE = 25 + def per_page + @per_page ||= begin + Integer(params[:per_page]) + rescue + 20 + end + end + def pagination_values - start = (current_page - 1) * PAGE_SIZE - [start, start + PAGE_SIZE] + start = (current_page - 1) * per_page + [start, start + per_page] end def paginated(qless_object, method, *args) @@ -180,7 +187,8 @@ def strftime(t) jobs = [] if tab == 'waiting' - jobs = queue.peek(20) + start, finish = pagination_values + jobs = queue.peek(finish)[start..finish] elsif filtered_tabs.include?(tab) jobs = paginated(queue.jobs, tab).map { |jid| client.jobs[jid] } end