From 2c2ea29d61bdcf56050a8ae0aac0f782e9082c7c Mon Sep 17 00:00:00 2001 From: Kerolos Zaki Date: Mon, 15 Jul 2024 20:19:15 +0300 Subject: [PATCH] fix(gacha/search-index): search-index was generating the wrong character rating in community packs pools (#412) --- search-index/mod.ts | 11 +++++++---- src/gacha.ts | 20 +++++++++----------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/search-index/mod.ts b/search-index/mod.ts index aad68d5e..bfa12174 100644 --- a/search-index/mod.ts +++ b/search-index/mod.ts @@ -144,20 +144,23 @@ const pool = async ( if (!media) return undefined; - const popularity = char.popularity ?? media.node.popularity ?? 1000; - const role = media.role; if (!role) return undefined; - const rating = new Rating({ role, popularity }).stars; + const rating = new Rating( + char.popularity ? { popularity: char.popularity } : { + role, + popularity: media.node.popularity ?? 1000, + }, + ).stars; return new IndexedCharacter( `${char.packId}:${char.id}`, `${media.node.packId}:${media.node.id}`, name, packs.aliasToArray(media.node.title), - popularity, + char.popularity ?? media.node.popularity ?? 1000, rating, role, ); diff --git a/src/gacha.ts b/src/gacha.ts index 7e353ff9..0e03a56f 100644 --- a/src/gacha.ts +++ b/src/gacha.ts @@ -184,26 +184,24 @@ export async function guaranteedPool( ); const validate = (character: Character | DisaggregatedCharacter): boolean => { - if ( - typeof character.popularity === 'number' && - new Rating({ popularity: character.popularity }).stars !== guarantee - ) { - return false; - } - // deno-lint-ignore no-non-null-assertion const edge = character.media && 'edges' in character.media! && character.media.edges[0]; - if (edge) { + if ( + typeof character.popularity === 'number' && + new Rating({ popularity: character.popularity }).stars === guarantee + ) { + return true; + } else if (edge) { const popularity = character.popularity || edge.node.popularity || lowest; - if (new Rating({ popularity, role: edge.role }).stars !== guarantee) { - return false; + if (new Rating({ popularity, role: edge.role }).stars === guarantee) { + return true; } } - return true; + return false; }; return {