Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit 699c406

Browse files
committed
chore: Batch Redis hdel operations for better performance
1 parent c0d585f commit 699c406

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

apps/master/src/util/updateScience.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { mainLog, mongo, redis } from "../index.js";
22
import pLimit from "p-limit";
33

44
const limit = pLimit(1);
5+
const BATCH_SIZE = 10000;
56

67
export default async function () {
78
return limit(async () => {
@@ -47,7 +48,6 @@ export default async function () {
4748
}));
4849

4950
// Batch the bulk operations for better performance
50-
const BATCH_SIZE = 10000;
5151
for (let i = 0; i < bulkOps.length; i += BATCH_SIZE) {
5252
const batch = bulkOps.slice(i, i + BATCH_SIZE);
5353
const res = await mongo
@@ -62,7 +62,11 @@ export default async function () {
6262
);
6363
}
6464

65-
await redis.hdel(key, ...entries.map(e => e.identifier));
65+
// Batch Redis hdel operations
66+
for (let i = 0; i < entries.length; i += BATCH_SIZE) {
67+
const batch = entries.slice(i, i + BATCH_SIZE);
68+
await redis.hdel(key, ...batch.map(e => e.identifier));
69+
}
6670
} else {
6771
log("No entries to update");
6872
}
@@ -86,7 +90,11 @@ export default async function () {
8690
});
8791

8892
if (delRedis.length) {
89-
await redis.hdel("pmd-api.scienceDeletes", ...delRedis);
93+
// Batch Redis hdel operations
94+
for (let i = 0; i < delRedis.length; i += BATCH_SIZE) {
95+
const batch = delRedis.slice(i, i + BATCH_SIZE);
96+
await redis.hdel("pmd-api.scienceDeletes", ...batch);
97+
}
9098
}
9199

92100
if (delRes.deletedCount) {

0 commit comments

Comments
 (0)