Fix updates not backfilling correctly

The backfill was applied to a copy of the item, so the changes were lost. This broke batching, which would apply to the first fetch but not to the second.
This commit is contained in:
Tim Van Baak 2025-03-02 21:12:34 -08:00
parent 2e01266843
commit 915fe7f9fe
2 changed files with 20 additions and 9 deletions

View File

@ -276,8 +276,8 @@ func updateWithFetchedItemsTx(
}
// Bulk update the existing items
for _, item := range updatedItems {
BackfillItem(&item, existingItemsById[item.Id])
for i := range updatedItems {
BackfillItem(&updatedItems[i], existingItemsById[updatedItems[i].Id])
}
if err = UpdateItems(db, updatedItems); err != nil {
return 0, 0, err

View File

@ -379,16 +379,27 @@ func TestSourceBatching(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if items[0].Id == "i" {
item1 = items[0]
item2 = items[1]
} else {
item1 = items[1]
item2 = items[0]
}
item1 = items[0]
item2 = items[1]
if item2.Tts != item1.Tts-1 {
t.Fatalf("expected different tts based on batch time, for %d and %d", item1.Tts, item2.Tts)
}
add, del, err = UpdateWithFetchedItems(db, "s", nil, []Item{item2}, now.Add(10*time.Second))
if add != 0 || del != 0 || err != nil {
t.Fatalf("expected only updates: %v", err)
}
itemsAgain, err := GetAllItemsForSource(db, "s", 0, 100)
if err != nil {
t.Fatal(err)
}
if itemsAgain[1].Id != item2.Id {
t.Error("unexpected return order")
}
if itemsAgain[1].Tts != item2.Tts {
t.Fatalf("batch tts not backfilled: %d vs %d", item2.Tts, itemsAgain[0].Tts)
}
}
func TestSourceLastUpdated(t *testing.T) {