| 393 | } |
| 394 | |
| 395 | export async function getComputeDeleteAddRemove( |
| 396 | tag: IndexTag, |
| 397 | currentFiles: FileStatsMap, |
| 398 | readFile: (path: string) => Promise<string>, |
| 399 | repoName: string | undefined, |
| 400 | ): Promise<[RefreshIndexResults, PathAndCacheKey[], MarkCompleteCallback]> { |
| 401 | const [add, remove, lastUpdated, markComplete] = await getAddRemoveForTag( |
| 402 | tag, |
| 403 | currentFiles, |
| 404 | readFile, |
| 405 | ); |
| 406 | |
| 407 | const compute: PathAndCacheKey[] = []; |
| 408 | const del: PathAndCacheKey[] = []; |
| 409 | const addTag: PathAndCacheKey[] = []; |
| 410 | const removeTag: PathAndCacheKey[] = []; |
| 411 | |
| 412 | for (const { path, cacheKey } of add) { |
| 413 | const existingTags = await getTagsFromGlobalCache(cacheKey, tag.artifactId); |
| 414 | if (existingTags.length > 0) { |
| 415 | addTag.push({ path, cacheKey }); |
| 416 | } else { |
| 417 | compute.push({ path, cacheKey }); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | for (const { path, cacheKey } of remove) { |
| 422 | const existingTags = await getTagsFromGlobalCache(cacheKey, tag.artifactId); |
| 423 | if (existingTags.length > 1) { |
| 424 | removeTag.push({ path, cacheKey }); |
| 425 | } else { |
| 426 | if (existingTags.length === 0) { |
| 427 | // console.warn("Existing tags should not be empty when trying to remove"); |
| 428 | } |
| 429 | |
| 430 | del.push({ path, cacheKey }); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | const results = { |
| 435 | compute, |
| 436 | del, |
| 437 | addTag, |
| 438 | removeTag, |
| 439 | }; |
| 440 | |
| 441 | const globalCacheIndex = await GlobalCacheCodeBaseIndex.create(); |
| 442 | |
| 443 | return [ |
| 444 | results, |
| 445 | lastUpdated, |
| 446 | async (items, resultType) => { |
| 447 | // Update tag catalog |
| 448 | await markComplete(items, resultType); |
| 449 | |
| 450 | // Update the global cache |
| 451 | const results: any = { |
| 452 | compute: [], |