deduplicateEntries removes duplicate entries by keeping only the most precise version reference for each repo+SHA combination. For example, if both "actions/cache@v4" and "actions/cache@v4.3.0" point to the same SHA and version, only "actions/cache@v4.3.0" is kept.
()
| 582 | // for each repo+SHA combination. For example, if both "actions/cache@v4" and "actions/cache@v4.3.0" |
| 583 | // point to the same SHA and version, only "actions/cache@v4.3.0" is kept. |
| 584 | func (c *ActionCache) deduplicateEntries() { |
| 585 | groups := c.groupEntriesByRepoAndSHA() |
| 586 | var toDelete []string |
| 587 | var deduplicationDetails []string |
| 588 | for ek, keys := range groups { |
| 589 | if len(keys) <= 1 { |
| 590 | continue |
| 591 | } |
| 592 | actionCacheLog.Printf("Found %d cache entries for %s with SHA %s", len(keys), ek.repo, truncateSHAForLog(ek.sha)) |
| 593 | keyInfos := buildDedupKeyInfos(keys) |
| 594 | if len(keyInfos) <= 1 { |
| 595 | continue |
| 596 | } |
| 597 | keepVersion, removedKeys, removedVersions := collectDedupRemovals(keyInfos) |
| 598 | for _, removedKey := range removedKeys { |
| 599 | toDelete = append(toDelete, removedKey) |
| 600 | actionCacheLog.Printf("Deduplicating: keeping %s, removing %s", keyInfos[0].key, removedKey) |
| 601 | } |
| 602 | deduplicationDetails = append(deduplicationDetails, fmt.Sprintf("%s: kept %s, removed %s", ek.repo, keepVersion, strings.Join(removedVersions, ", "))) |
| 603 | } |
| 604 | c.deleteDedupEntries(toDelete) |
| 605 | if len(toDelete) > 0 { |
| 606 | actionCacheLog.Printf("Deduplicated %d entries, %d entries remaining", len(toDelete), len(c.Entries)) |
| 607 | for _, detail := range deduplicationDetails { |
| 608 | actionCacheLog.Printf("Deduplication detail: %s", detail) |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | type deduplicationKey struct { |
| 614 | repo string |
no test coverage detected