Skip to content

Commit

Permalink
chore: check at batch of 10
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovler-Young committed Jun 24, 2024
1 parent cbfe1e8 commit 810bf19
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/lib/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,32 @@ const handle_source = async (ctx: Context, source_type: string, source_id: strin
}
};

for (const bvid of bvids) {
const result = await api.check(new Bvid(bvid));
if (result.isSome()) {
existingCount++;
} else {
newCount++;
newBvids.push(bvid);
await api.add(new Bvid(bvid));
}
processedCount++;
const BATCH_SIZE = 10;
await updateStatus();

for (let i = 0; i < bvids.length; i += BATCH_SIZE) {
const batch = bvids.slice(i, i + BATCH_SIZE);

const results = await Promise.all(
batch.map(bvid => api.check(new Bvid(bvid)))
);

for (let j = 0; j < results.length; j++) {
const result = results[j];
const bvid = batch[j];

if (result.isSome()) {
existingCount++;
} else {
newCount++;
newBvids.push(bvid);
await api.add(new Bvid(bvid));
}
processedCount++;
}
if (
(chat_type === "private" && processedCount % 1 === 0) ||
(chat_type !== "private" && processedCount % 5 === 0) ||
(chat_type !== "private" && processedCount % 6 === 0) ||
processedCount === bvids.length
) {
await updateStatus();
Expand Down

0 comments on commit 810bf19

Please sign in to comment.