Skip to content

Commit

Permalink
fix(gacha/search-index): search-index was generating the wrong charac…
Browse files Browse the repository at this point in the history
…ter rating in community packs pools (#412)
  • Loading branch information
ker0olos authored Jul 15, 2024
1 parent fd3b273 commit 2c2ea29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
11 changes: 7 additions & 4 deletions search-index/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
20 changes: 9 additions & 11 deletions src/gacha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2c2ea29

Please sign in to comment.