Permalink
Browse files

CODEBASE-350: kaminari performance terrible with large number of page…

…s; Apply (as a monkey patch) code from Kaminari pull request #154 (issue #137)
  • Loading branch information...
1 parent 5ad63cb commit 0e64d634fbfe7e8a5bab7e655d261aa34433b75d Chris Beer committed Sep 28, 2011
@@ -11,7 +11,7 @@
<%= prev_page_tag %>
<%= next_page_tag %>
<div class="page_links">
- <% each_page do |page| -%>
+ <% each_relevant_page do |page| -%>
<% if page.left_outer? || page.right_outer? || page.inside_window? -%>
<%= page_tag page %>
<% elsif !page.was_truncated? -%>
View
@@ -1,5 +1,6 @@
# -*- encoding : utf-8 -*-
require 'kaminari'
+require 'blacklight/kaminari_relevant_pages_patch'
require 'marc'
require 'rsolr'
require 'rsolr-ext'
@@ -0,0 +1,37 @@
+module Blacklight
+ module KaminariRelevantPagesPatch
+ module Windows
+ def relevant_pages options
+ [left_window(options), inside_window(options), right_window(options)].map(&:to_a).flatten.uniq.sort.reject { |x| x < 1 or x > options[:num_pages] }
+ end
+
+ def all_pages options
+ 1.upto(options[:num_pages])
+ end
+
+ protected
+ def left_window options
+ 1.upto(options[:left] + 1)
+ end
+
+ def right_window options
+ (options[:num_pages] - options[:right]).upto(options[:num_pages])
+ end
+
+ def inside_window options
+ (options[:current_page] - options[:window]).upto(options[:current_page] + options[:window])
+ end
+ end
+
+ include Windows
+ def each_relevant_page
+ return to_enum(:each_relevant_page) unless block_given?
+
+ relevant_pages(@window_options.merge(@options)).each do |i|
+ yield Kaminari::Helpers::Paginator::PageProxy.new(@window_options.merge(@options), i, @last)
+ end
+ end
+ end
+end
+
+Kaminari::Helpers::Paginator.send(:include, Blacklight::KaminariRelevantPagesPatch)

0 comments on commit 0e64d63

Please sign in to comment.