@@ -2,6 +2,7 @@ import { mainLog, mongo, redis } from "../index.js";
22import pLimit from "p-limit" ;
33
44const limit = pLimit ( 1 ) ;
5+ const BATCH_SIZE = 10000 ;
56
67export 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