Skip to content

Commit

Permalink
Paginate apikeys#index
Browse files Browse the repository at this point in the history
To avoid unbounded db query
  • Loading branch information
segiddins authored and simi committed Jul 24, 2024
1 parent 6e27b38 commit e2f1aef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/controllers/api_keys_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ApiKeysController < ApplicationController
before_action :disable_cache, only: :index
before_action :set_page, only: :index

include ApiKeyable

Expand All @@ -8,7 +9,7 @@ class ApiKeysController < ApplicationController

def index
@api_key = session.delete(:api_key)
@api_keys = current_user.api_keys.unexpired.not_oidc.preload(ownership: :rubygem)
@api_keys = current_user.api_keys.unexpired.not_oidc.preload(ownership: :rubygem).page(@page)
redirect_to new_profile_api_key_path if @api_keys.empty?
end

Expand Down
9 changes: 9 additions & 0 deletions app/views/api_keys/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
</div>
<% end %>

<header class="gems__header">
<p class="gems__meter">
<%= page_entries_info @api_keys, entry_name: 'API keys' %>
</p>
</header>

<div class="t-body">
<table class="owners__table">
<tr class="owners__row owners__header">
Expand Down Expand Up @@ -85,6 +91,7 @@
</td>
</tr>
<% end %>

<tr class="owners__row">
<td class="owners__cell">
</td>
Expand Down Expand Up @@ -114,6 +121,8 @@
</tr>
</table>

<%= paginate @api_keys %>

<p><%= button_to t(".new_key"), new_profile_api_key_path, method: "get", class: "form__submit" %></p>
<% if current_user.oidc_api_key_roles.any? %>
<h2 class="t-display"><%= link_to t("oidc.api_key_roles.index.api_key_roles"), profile_oidc_api_key_roles_path, class: "t-link t-underline" %></h2>
Expand Down

0 comments on commit e2f1aef

Please sign in to comment.