mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 10:35:30 +00:00
BUGFIX: keep fts5 tables syncronized
This commit is contained in:
@@ -206,6 +206,18 @@ func (p *OrtEditPage) POST(engine *templating.Engine, app core.App) HandleFunc {
|
||||
return p.renderError(engine, app, e, "Speichern fehlgeschlagen.")
|
||||
}
|
||||
|
||||
// Update FTS5 index for place and all related entries asynchronously
|
||||
go func(appInstance core.App, placeID string) {
|
||||
freshPlace, err := dbmodels.Places_ID(appInstance, placeID)
|
||||
if err != nil {
|
||||
appInstance.Logger().Error("Failed to load place for FTS5 update", "place_id", placeID, "error", err)
|
||||
return
|
||||
}
|
||||
if err := dbmodels.UpdateFTS5PlaceAndRelatedEntries(appInstance, freshPlace); err != nil {
|
||||
appInstance.Logger().Error("Failed to update FTS5 index for place and related records", "place_id", placeID, "error", err)
|
||||
}
|
||||
}(app, place.Id)
|
||||
|
||||
redirect := fmt.Sprintf("/ort/%s/edit?saved_message=%s", id, url.QueryEscape("Änderungen gespeichert."))
|
||||
return e.Redirect(http.StatusSeeOther, redirect)
|
||||
}
|
||||
@@ -288,6 +300,20 @@ func (p *OrtEditPage) POSTDelete(engine *templating.Engine, app core.App) Handle
|
||||
})
|
||||
}
|
||||
|
||||
// Delete place from FTS5 and update all affected entries asynchronously
|
||||
go func(appInstance core.App, placeID string, affectedEntries []*dbmodels.Entry) {
|
||||
if err := dbmodels.DeleteFTS5Place(appInstance, placeID); err != nil {
|
||||
appInstance.Logger().Error("Failed to delete place from FTS5", "place_id", placeID, "error", err)
|
||||
}
|
||||
|
||||
// Update FTS5 for all entries that had this place
|
||||
for _, entry := range affectedEntries {
|
||||
if err := updateEntryFTS5(appInstance, entry); err != nil {
|
||||
appInstance.Logger().Error("Failed to update FTS5 for entry after place deletion", "entry_id", entry.Id, "error", err)
|
||||
}
|
||||
}
|
||||
}(app, place.Id, entries)
|
||||
|
||||
return e.JSON(http.StatusOK, map[string]any{
|
||||
"success": true,
|
||||
"redirect": "/orte",
|
||||
|
||||
Reference in New Issue
Block a user