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