Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions repository/inventory_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,29 @@ func (i InventoryRepo) Add(ctx context.Context, key string, assets map[string]in
func (i InventoryRepo) Remove(_ context.Context, _ string) error {
return nil
}

func (i InventoryRepo) Get(ctx context.Context, key string) (map[string]int64, error) {
var inventory map[string]int64
err := i.cache.Get(ctx, string(domain.NewKeyInventory(key)), &inventory)
var (
inventory map[string]int64
inventoryKey = string(domain.NewKeyInventory(key))
)

err := i.cache.Get(ctx, inventoryKey, &inventory)
if err != nil && !errors.Is(err, domain.ErrCacheNotFound) {
return inventory, err
// Backwards compatibility:
// Before PR #404, inventory configs were stored as map[string]string.
// After PR #404, they use map[string]int64 for SSE optimizations.
//
// To support upgrades from older versions (<= 2.0.12), try reading the old format
// and convert it to the new format by setting all values to 0.
backup := map[string]string{}
if err := i.cache.Get(ctx, inventoryKey, &backup); err != nil {
return nil, err
}

for k := range backup {
inventory[k] = 0
}
}

return inventory, nil
Expand Down