diff --git a/core/source.go b/core/source.go index 29692b5..a5943c4 100644 --- a/core/source.go +++ b/core/source.go @@ -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 diff --git a/core/source_test.go b/core/source_test.go index bb90ba7..f959154 100644 --- a/core/source_test.go +++ b/core/source_test.go @@ -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) {