feat(pokemon): sort by display_id instead of internal id
Update schema to replace sort_order index with display_id index Apply display_id ordering to global search, lists, and relations Update design documentation to reflect the new sorting behavior
This commit is contained in:
@@ -1335,7 +1335,8 @@ CREATE INDEX IF NOT EXISTS environments_sort_order_idx ON environments(sort_orde
|
||||
CREATE INDEX IF NOT EXISTS skills_sort_order_idx ON skills(sort_order, id);
|
||||
CREATE INDEX IF NOT EXISTS favorite_things_sort_order_idx ON favorite_things(sort_order, id);
|
||||
CREATE INDEX IF NOT EXISTS pokemon_types_sort_order_idx ON pokemon_types(sort_order, id);
|
||||
CREATE INDEX IF NOT EXISTS pokemon_sort_order_idx ON pokemon(sort_order, id);
|
||||
DROP INDEX IF EXISTS pokemon_sort_order_idx;
|
||||
CREATE INDEX IF NOT EXISTS pokemon_display_order_idx ON pokemon(is_event_item, display_id, id);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS pokemon_display_event_item_key ON pokemon(display_id, is_event_item);
|
||||
CREATE INDEX IF NOT EXISTS acquisition_methods_sort_order_idx ON acquisition_methods(sort_order, id);
|
||||
CREATE INDEX IF NOT EXISTS items_sort_order_idx ON items(sort_order, id);
|
||||
|
||||
@@ -2871,7 +2871,7 @@ export async function globalSearch(paramsQuery: QueryParams = {}, locale = defau
|
||||
${pokemonImageJson('p')} AS image
|
||||
FROM pokemon p
|
||||
WHERE ${pokemonName} ILIKE $1
|
||||
ORDER BY p.id
|
||||
ORDER BY p.display_id, p.id
|
||||
LIMIT $2
|
||||
`,
|
||||
[pattern, limit]
|
||||
@@ -5757,7 +5757,7 @@ export async function listPokemon(paramsQuery: QueryParams, locale = defaultLoca
|
||||
}
|
||||
|
||||
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
||||
return queryMaybePaged(`${pokemonProjection(locale)} ${whereClause} ORDER BY p.id`, params, paramsQuery);
|
||||
return queryMaybePaged(`${pokemonProjection(locale)} ${whereClause} ORDER BY p.display_id, p.id`, params, paramsQuery);
|
||||
}
|
||||
|
||||
export async function getPokemon(id: number, locale = defaultLocale) {
|
||||
@@ -5963,6 +5963,7 @@ export async function getPokemon(id: number, locale = defaultLocale) {
|
||||
scored_pokemon."favoriteThingMatchCount" DESC,
|
||||
scored_pokemon."environmentIsOpposite" DESC,
|
||||
scored_pokemon."favoriteThingOppositeCount" DESC,
|
||||
related_pokemon.display_id,
|
||||
related_pokemon.id
|
||||
`,
|
||||
[id]
|
||||
@@ -6351,7 +6352,7 @@ export async function listHabitats(paramsQuery: QueryParams = {}, locale = defau
|
||||
'name', pokemon_rows.name,
|
||||
'isEventItem', pokemon_rows.is_event_item
|
||||
)
|
||||
ORDER BY pokemon_rows.id
|
||||
ORDER BY pokemon_rows.display_id, pokemon_rows.id
|
||||
)
|
||||
FROM (
|
||||
SELECT DISTINCT p.id, p.display_id, ${pokemonName} AS name, p.is_event_item
|
||||
@@ -6425,7 +6426,7 @@ export async function getHabitat(id: number, locale = defaultLocale) {
|
||||
JOIN pokemon p ON p.id = hp.pokemon_id
|
||||
JOIN maps m ON m.id = hp.map_id
|
||||
WHERE hp.habitat_id = $1
|
||||
ORDER BY hp.rarity, p.id, ${orderByEntity('m')}
|
||||
ORDER BY hp.rarity, p.display_id, p.id, ${orderByEntity('m')}
|
||||
`,
|
||||
[id]
|
||||
),
|
||||
@@ -6836,7 +6837,7 @@ export async function getItem(id: number, locale = defaultLocale) {
|
||||
JOIN skills s ON s.id = psid.skill_id
|
||||
WHERE psid.item_id = $1
|
||||
AND s.has_item_drop = true
|
||||
ORDER BY p.id, ${orderByEntity('s')}
|
||||
ORDER BY p.display_id, p.id, ${orderByEntity('s')}
|
||||
`,
|
||||
[id]
|
||||
),
|
||||
@@ -6874,7 +6875,7 @@ export async function getItem(id: number, locale = defaultLocale) {
|
||||
WHERE ps.pokemon_id = p.id
|
||||
AND trading_skill.has_trading = true
|
||||
)
|
||||
ORDER BY pti.preference DESC, p.id
|
||||
ORDER BY pti.preference DESC, p.display_id, p.id
|
||||
`,
|
||||
[id]
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user