Skip to content

Commit 917e0b8

Browse files
committed
Migrate from Kaminari to pagy
1 parent 0eb3e68 commit 917e0b8

38 files changed

+297
-121
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ gem "good_job", "~> 3.99"
1919
gem "gravtastic", "~> 3.2"
2020
gem "honeybadger", "~> 5.5.1", require: false # see https://github.com/rubygems/rubygems.org/pull/4598
2121
gem "http_accept_language", "~> 2.1"
22-
gem "kaminari", "~> 1.2"
22+
gem "pagy", "~> 9.0"
2323
gem "launchdarkly-server-sdk", "~> 8.7"
2424
gem "mail", "~> 2.8"
2525
gem "octokit", "~> 9.1"

Gemfile.lock

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,6 @@ GEM
326326
faraday (~> 2.0)
327327
faraday-follow_redirects
328328
jwt (2.7.1)
329-
kaminari (1.2.2)
330-
activesupport (>= 4.1.0)
331-
kaminari-actionview (= 1.2.2)
332-
kaminari-activerecord (= 1.2.2)
333-
kaminari-core (= 1.2.2)
334-
kaminari-actionview (1.2.2)
335-
actionview
336-
kaminari-core (= 1.2.2)
337-
kaminari-activerecord (1.2.2)
338-
activerecord
339-
kaminari-core (= 1.2.2)
340-
kaminari-core (1.2.2)
341329
language_server-protocol (3.17.0.3)
342330
launchdarkly-server-sdk (8.7.0)
343331
concurrent-ruby (~> 1.1)
@@ -836,7 +824,6 @@ DEPENDENCIES
836824
honeybadger (~> 5.5.1)
837825
http_accept_language (~> 2.1)
838826
importmap-rails (~> 2.0)
839-
kaminari (~> 1.2)
840827
launchdarkly-server-sdk (~> 8.7)
841828
launchy (~> 3.0)
842829
letter_opener (~> 1.10)
@@ -1035,10 +1022,6 @@ CHECKSUMS
10351022
json (2.7.2) sha256=1898b5cbc81cd36c0fd4d0b7ad2682c39fb07c5ff682fc6265f678f550d4982c
10361023
json-jwt (1.16.6) sha256=ab451f9cd8743cecc4137f4170806046c1d8a6d4ee6e8570e0b5c958409b266c
10371024
jwt (2.7.1) sha256=07357cd2f180739b2f8184eda969e252d850ac996ed0a23f616e8ff0a90ae19b
1038-
kaminari (1.2.2) sha256=c4076ff9adccc6109408333f87b5c4abbda5e39dc464bd4c66d06d9f73442a3e
1039-
kaminari-actionview (1.2.2) sha256=1330f6fc8b59a4a4ef6a549ff8a224797289ebf7a3a503e8c1652535287cc909
1040-
kaminari-activerecord (1.2.2) sha256=0dd3a67bab356a356f36b3b7236bcb81cef313095365befe8e98057dd2472430
1041-
kaminari-core (1.2.2) sha256=3bd26fec7370645af40ca73b9426a448d09b8a8ba7afa9ba3c3e0d39cdbb83ff
10421025
language_server-protocol (3.17.0.3) sha256=3d5c58c02f44a20d972957a9febe386d7e7468ab3900ce6bd2b563dd910c6b3f
10431026
launchdarkly-server-sdk (8.7.0) sha256=062e7dc42c2884ed9deed42c49937917faa911128a659386e4bd45d1ad1506eb
10441027
launchy (3.0.1) sha256=b7fa60bda0197cf57614e271a250a8ca1f6a34ab889a3c73f67ec5d57c8a7f2c

app/assets/stylesheets/modules/nav/nav--paginated.css

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,27 @@
4646
margin-right: 8px;
4747
margin-left: 8px; }
4848

49-
.pagination {
49+
nav.pagy {
5050
margin-top: 90px;
5151
position: relative;
5252
width: 100%;
5353
overflow: auto;
5454
text-align: center; }
55-
.pagination a, .pagination em {
55+
nav.pagy a, nav.pagy em {
5656
margin-right: 8px;
5757
margin-left: 8px;
5858
font-style: normal; }
59-
.pagination a {
59+
nav.pagy a {
6060
color: #9da2ab;
6161
transition-duration: 0.25s;
6262
transition-property: color;
6363
outline: none; }
64-
.pagination a:hover, .pagination a:focus, .pagination a:active {
64+
nav.pagy a:hover, nav.pagy a:focus, nav.pagy a:active {
6565
color: #141c22; }
66-
.pagination .previous_page.disabled, .pagination .next_page.disabled {
66+
nav.pagy a:first-child:not([href]), nav.pagy a:last-child:not([href]) {
6767
color: #9da2ab; }
68-
.pagination .previous_page.disabled:hover, .pagination .previous_page.disabled:focus, .pagination .previous_page.disabled:active, .pagination .next_page.disabled:hover, .pagination .next_page.disabled:focus, .pagination .next_page.disabled:active {
68+
nav.pagy a:first-child:not([href]):hover, nav.pagy a:first-child:not([href]):focus, nav.pagy a:first-child:not([href]):active, nav.pagy nav.pagy a:last-child:not([href]):hover, nav.pagy nav.pagy a:last-child:not([href]):focus, nav.pagy nav.pagy a:last-child:not([href]):active {
6969
color: #9da2ab; }
70-
.pagination .previous_page {
71-
position: absolute;
72-
left: 0; }
73-
.pagination .next_page {
74-
position: absolute;
75-
right: 0; }
76-
.pagination .current {
70+
nav.pagy .current {
71+
color: #000;
7772
margin: 0 8px; }

app/controllers/api/v1/timeframe_versions_controller.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ class InvalidTimeframeParameterError < StandardError; end
66
MAXIMUM_TIMEFRAME_QUERY_IN_DAYS = 7
77

88
def index
9-
render_rubygems(
10-
Version.created_between(from_time, to_time).page(@page)
11-
)
9+
render_rubygems(*pagy(Version.created_between(from_time, to_time)))
1210
end
1311

1412
private
@@ -35,12 +33,13 @@ def to_time
3533
raise InvalidTimeframeParameterError, 'the "to" parameter must be iso8601 formatted'
3634
end
3735

38-
def render_rubygems(versions)
36+
def render_rubygems(pagy, versions)
3937
rubygems = versions.includes(:dependencies, :gem_download, rubygem: %i[linkset gem_download]).map do |version|
4038
payload = version.rubygem.payload(version)
4139
payload.merge(version.as_json)
4240
end
4341

42+
pagy_headers_merge(pagy)
4443
respond_to do |format|
4544
format.json { render json: rubygems }
4645
format.yaml { render yaml: rubygems }

app/controllers/api_keys_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class ApiKeysController < ApplicationController
88
verify_session_before
99

1010
def index
11-
@api_key = session.delete(:api_key)
12-
@api_keys = current_user.api_keys.unexpired.not_oidc.preload(ownership: :rubygem).page(@page)
11+
@api_key = session.delete(:api_key)
12+
@api_keys_pagy, @api_keys = pagy(current_user.api_keys.unexpired.not_oidc.preload(ownership: :rubygem))
1313
redirect_to new_profile_api_key_path if @api_keys.empty?
1414
end
1515

app/controllers/application_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class ApplicationController < ActionController::Base
33
include Pundit::Authorization
44
include ApplicationMultifactorMethods
55
include TraceTagger
6+
include Pagy::Backend
67

78
helper ActiveSupport::NumberHelper
89

app/controllers/news_controller.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ class NewsController < ApplicationController
22
before_action -> { set_page Gemcutter::NEWS_MAX_PAGES }
33

44
def show
5-
@rubygems = Rubygem.preload(:latest_version, :gem_download)
6-
.news(Gemcutter::NEWS_DAYS_LIMIT)
7-
.page(@page)
8-
.per(Gemcutter::NEWS_PER_PAGE)
5+
@rubygems_pagy, @rubygems = pagy(
6+
Rubygem.preload(:latest_version, :gem_download)
7+
.news(Gemcutter::NEWS_DAYS_LIMIT),
8+
limit: Gemcutter::NEWS_MAX_PAGES
9+
)
10+
911
limit_total_count
1012
end
1113

1214
def popular
1315
@title = t(".title")
14-
@rubygems = Rubygem.preload(:latest_version, :gem_download)
15-
.popular(Gemcutter::POPULAR_DAYS_LIMIT)
16-
.page(@page)
17-
.per(Gemcutter::NEWS_PER_PAGE)
16+
@rubygems_pagy, @rubygems = pagy(Rubygem.preload(:latest_version, :gem_download)
17+
.popular(Gemcutter::POPULAR_DAYS_LIMIT),
18+
limit: Gemcutter::NEWS_MAX_PAGES)
1819
limit_total_count
1920

2021
render :show

app/controllers/oidc/api_key_roles_controller.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ class OIDC::ApiKeyRolesController < ApplicationController
1111
before_action :set_page, only: :index
1212

1313
def index
14-
@api_key_roles = current_user.oidc_api_key_roles.active.includes(:provider)
15-
.page(@page)
16-
.strict_loading
14+
@api_key_roles_pagy, @api_key_roles = pagy(current_user.oidc_api_key_roles.active.includes(:provider).strict_loading)
1715
end
1816

1917
def show
20-
@id_tokens = @api_key_role.id_tokens.order(id: :desc).includes(:api_key)
21-
.page(0).per(10)
22-
.strict_loading
18+
@id_tokens_pagy, @id_tokens = pagy(@api_key_role.id_tokens.order(id: :desc).includes(:api_key).strict_loading, limit: 10)
2319
respond_to do |format|
2420
format.json do
2521
render json: @api_key_role

app/controllers/oidc/providers_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class OIDC::ProvidersController < ApplicationController
88
before_action :set_page, only: :index
99

1010
def index
11-
providers = OIDC::Provider.strict_loading.page(@page)
12-
render OIDC::Providers::IndexView.new(providers:)
11+
providers_pagy, providers = pagy(OIDC::Provider.strict_loading)
12+
render OIDC::Providers::IndexView.new(providers_pagy:, providers:)
1313
end
1414

1515
def show

app/controllers/ownership_calls_controller.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ class OwnershipCallsController < ApplicationController
1313

1414
def index
1515
set_page
16-
@ownership_calls = OwnershipCall.opened.includes(:user, rubygem: %i[latest_version gem_download]).order(created_at: :desc)
17-
.page(@page)
18-
.per(Gemcutter::OWNERSHIP_CALLS_PER_PAGE)
16+
@ownership_calls_pagy, @ownership_calls = pagy(
17+
OwnershipCall.opened.includes(:user, rubygem: %i[latest_version gem_download]).order(created_at: :desc),
18+
limit: Gemcutter::OWNERSHIP_CALLS_PER_PAGE
19+
)
1920
end
2021

2122
def create

0 commit comments

Comments
 (0)