Permalink
Browse files

Paginate the Artefacts list because its slow

In development, with ~3,200 artefacts, load time went from 7600ms to 280ms.
  • Loading branch information...
1 parent 2a1dc6e commit 107a7545bbb9134409c8089d14f5b3bdaa4e526e @jamiecobbett jamiecobbett committed Mar 20, 2013
View
@@ -24,6 +24,7 @@ gem 'rummageable', "~> 0.3.0"
gem "mongoid", "~> 2.4.2"
gem "mongoid_rails_migrations", "1.0.0"
gem "mongo", "1.6.2"
+gem "kaminari", "0.14.1"
gem "bson_ext", "1.6.2"
gem "bson", "1.6.2"
gem 'lograge', '~> 0.1.0'
View
@@ -144,6 +144,9 @@ GEM
json (1.7.7)
jwt (0.1.8)
multi_json (>= 1.5)
+ kaminari (0.14.1)
+ actionpack (>= 3.0.0)
+ activesupport (>= 3.0.0)
kgio (2.7.4)
kramdown (0.13.8)
launchy (2.1.2)
@@ -325,6 +328,7 @@ DEPENDENCIES
govuk_content_models (= 4.11.0)
jquery-rails (= 2.0.2)
jquery-ui-rails (= 3.0.1)
+ kaminari (= 0.14.1)
launchy
less-rails-bootstrap
lograge (~> 0.1.0)
@@ -13,35 +13,6 @@
*= require formtastic-bootstrap
*/
-/* Styling for tablesorter plugin */
-table thead tr th {
- cursor: pointer;
-}
-
-table thead tr th.header {
- padding-right: 20px;
- background: url(bg.gif) no-repeat right 75%;
-}
-
-table thead tr .header.headerSortUp {
- background: url(asc.gif) no-repeat right 75%;
-}
-
-table thead tr .header.headerSortDown {
- background: url(desc.gif) no-repeat right 75%;
-}
-
-table#artefact-list tr.archived {
- opacity: 0.5;
-}
-
-
-tr.top-level-section {
- font-weight: bold;
-}
-
-/* end of tablesorter styling */
-
.related-artefact-group, .curated-artefact-group {
margin-bottom: 10px;
}
@@ -79,3 +50,18 @@ tr.top-level-section {
height: 16px;
background: url(language_cy.png) no-repeat center center;
}
+
+
+/* Pagination tweaks copied from Migratorator */
+.pagination span.current, .pagination span.gap {
+ float: left;
+ padding: 0 14px;
+ line-height: 34px;
+ text-decoration: none;
+ border: 1px solid #DDD;
+ border-left-width: 0;
+}
+.pagination span.current { background: #eee; }
+.pagination span:first-child, .pagination span:first-child a {
+ border-left-width: 1px;
+}
@@ -6,6 +6,8 @@ class ArtefactsController < ApplicationController
respond_to :html, :json
+ ITEMS_PER_PAGE = 100
+
def index
@section = params[:section] || "all"
if @section != "all"
@@ -16,6 +18,7 @@ def index
else
@artefacts = Artefact.order_by([[:name, :asc]])
end
+ @artefacts = @artefacts.page(params[:page]).per(ITEMS_PER_PAGE)
respond_with @artefacts, @tag_collection
end
@@ -50,15 +50,8 @@
<% end %>
</tbody>
</table>
+ <%= paginate @artefacts %>
</div><!-- ./span10 -->
</div><!-- ./row fluid -->
</div><!-- ./span12 -->
</div><!-- ./row-fluid-->
-
-<%= content_for :extra_javascript do %>
- <script type="text/javascript">
- $(function () {
- $('#artefact-list').tablesorter();
- });
- </script>
-<% end %>
View
@@ -4,6 +4,7 @@
require "action_mailer/railtie"
require "rails/test_unit/railtie"
require "sprockets/railtie"
+require 'kaminari' # has to be loaded before the models, otherwise the methods aren't added
require "govuk_content_models"
if defined?(Bundler)

0 comments on commit 107a754

Please sign in to comment.