MCPcopy Index your code
hub / github.com/omkarcloud/botasaurus / deleteItemsByFilter

Method deleteItemsByFilter

js/botasaurus-js/src/cache.ts:233–268  ·  view source on GitHub ↗
(func: Function | string, items: any[], shouldDeleteItem: (key: any, data: any) => boolean)

Source from the content-addressed store, hash-verified

231 }
232
233 static async deleteItemsByFilter(func: Function | string, items: any[], shouldDeleteItem: (key: any, data: any) => boolean): Promise<number> {
234 const testItems = Cache.filterItemsInCache(func, items);
235 const collectedHoneypots: any[] = [];
236
237 for (const key of testItems) {
238 try {
239 const data = Cache.get(func, key);
240 if (shouldDeleteItem(key, data)) {
241 collectedHoneypots.push(key);
242 }
243 } catch (error) {
244 // Ignore error
245 }
246 }
247
248 if (collectedHoneypots.length > 0) {
249 const path = './output/items_to_be_deleted.json';
250 formatWriteJson(collectedHoneypots, path);
251 while (true) {
252 const result = await prompt(`Should we delete ${collectedHoneypots.length} items in ${path}? (Y/n): `);
253
254 if (isAffirmative(result)) {
255 console.log(`Deleting ${collectedHoneypots.length} items...`);
256 Cache.deleteItems(func, collectedHoneypots);
257 break;
258 } else if (isNegative(result)) {
259 console.log('No items were deleted');
260 break;
261 }
262 }
263 } else {
264 console.log('No items were deleted');
265 }
266
267 return collectedHoneypots.length;
268 }
269
270 static filterItemsInCache(func: Function | string, items: any[]): any[] {
271 const cachedItems = new Set(Cache.getItemsHashes(func));

Callers

nothing calls this directly

Calls 7

promptFunction · 0.90
isAffirmativeFunction · 0.85
isNegativeFunction · 0.85
deleteItemsMethod · 0.80
filterItemsInCacheMethod · 0.45
getMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected