fix: IndexNow hears of deleted and edited records

RecordDeleted marks the listed rows it excludes and RecordSaved the rows
whose lastmod it moves (indexnow_pending_at); the next rebuild sends
them to IndexNow as removed or changed and clears the marks. RecordSaved
checks for a nil event before reading it. TestIndexNow now deletes and
edits through the record events, as the admin does.
This commit is contained in:
Jakub Zych
2026-11-04 23:02:09 +01:00
parent 6b67ab759b
commit f58d55555c
8 changed files with 147 additions and 12 deletions

View File

@@ -161,3 +161,24 @@ func init() {
func page1(id int, slug string, mod time.Time) fakeRecord {
return fakeRecord{ID: id, Published: true, LastMod: mod, Locales: []pact.ContentLocale{{Locale: "en", URL: "/pages/" + slug, Title: "Page " + slug}}}
}
// deleteRecord removes a record of typ from the store and fires
// pact.RecordDeleted for its model, as the admin does after a delete.
func (e *sitemapEnv) deleteRecord(t *testing.T, typ, model string, id int) {
t.Helper()
contentStore.remove(typ, id)
if err := e.app.Events.Fire(context.Background(), &pact.RecordDeleted{Model: model, ID: strconv.Itoa(id)}); err != nil {
t.Fatal(err)
}
}
// editRecord replaces a record of typ in the store and fires
// pact.RecordSaved for its model with the changed attributes, as the admin
// does after a save.
func (e *sitemapEnv) editRecord(t *testing.T, typ, model string, rec fakeRecord, changes ...pact.RecordChange) {
t.Helper()
contentStore.put(typ, rec)
if err := e.app.Events.Fire(context.Background(), &pact.RecordSaved{Model: model, ID: strconv.Itoa(rec.ID), Changes: changes}); err != nil {
t.Fatal(err)
}
}