PERF: introduce a basic api key serializer

For better performances when listing all the API keys.

Loading all the "api key scopes" is slow and not required when showing the list of all the api keys.
This commit is contained in:
Régis Hanol 2024-04-24 18:52:31 +02:00
parent 2bab1df461
commit 7dcd707c59
2 changed files with 13 additions and 2 deletions

View File

@ -13,12 +13,16 @@ class Admin::ApiController < Admin::AdminController
keys =
ApiKey
.where(hidden: false)
.includes(:user, :api_key_scopes)
.includes(:user)
.order("revoked_at DESC NULLS FIRST, created_at DESC")
.offset(offset)
.limit(limit)
render_json_dump(keys: serialize_data(keys, ApiKeySerializer), offset: offset, limit: limit)
render_json_dump(
keys: serialize_data(keys, BasicApiKeySerializer),
offset: offset,
limit: limit,
)
end
def show

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class BasicApiKeySerializer < ApplicationSerializer
attributes :id, :truncated_key, :description, :created_at, :last_used_at, :revoked_at
has_one :user, serializer: BasicUserSerializer, embed: :objects
end