mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 10:35:30 +00:00
BUGFIX: FTS5 -- make sure only minimum updates happen
This commit is contained in:
@@ -303,6 +303,9 @@ func (p *PersonEditPage) POST(engine *templating.Engine, app core.App) HandleFun
|
||||
return p.renderError(engine, app, e, "Ungültiger Status.")
|
||||
}
|
||||
|
||||
// Capture old name (entries and contents depend on agent name)
|
||||
oldName := agent.Name()
|
||||
|
||||
user := req.User()
|
||||
if err := app.RunInTransaction(func(tx core.App) error {
|
||||
applyPersonForm(agent, formdata, name, status, user)
|
||||
@@ -312,17 +315,27 @@ func (p *PersonEditPage) POST(engine *templating.Engine, app core.App) HandleFun
|
||||
return p.renderError(engine, app, e, "Speichern fehlgeschlagen.")
|
||||
}
|
||||
|
||||
// Update FTS5 index for agent and all related entries/contents asynchronously
|
||||
go func(appInstance core.App, agentID string) {
|
||||
// Check if name changed (entries and contents store agent name)
|
||||
nameChanged := agent.Name() != oldName
|
||||
|
||||
// Update FTS5 index for agent and conditionally update related entries/contents asynchronously
|
||||
go func(appInstance core.App, agentID string, updateRelated bool) {
|
||||
freshAgent, err := dbmodels.Agents_ID(appInstance, agentID)
|
||||
if err != nil {
|
||||
appInstance.Logger().Error("Failed to load agent for FTS5 update", "agent_id", agentID, "error", err)
|
||||
return
|
||||
}
|
||||
if err := dbmodels.UpdateFTS5AgentAndRelated(appInstance, freshAgent); err != nil {
|
||||
appInstance.Logger().Error("Failed to update FTS5 index for agent and related records", "agent_id", agentID, "error", err)
|
||||
// If name changed, update agent + entries + contents. Otherwise just update agent.
|
||||
if updateRelated {
|
||||
if err := dbmodels.UpdateFTS5AgentAndRelated(appInstance, freshAgent); err != nil {
|
||||
appInstance.Logger().Error("Failed to update FTS5 index for agent and related records", "agent_id", agentID, "error", err)
|
||||
}
|
||||
} else {
|
||||
if err := dbmodels.UpdateFTS5Agent(appInstance, freshAgent); err != nil {
|
||||
appInstance.Logger().Error("Failed to update FTS5 index for agent", "agent_id", agentID, "error", err)
|
||||
}
|
||||
}
|
||||
}(app, agent.Id)
|
||||
}(app, agent.Id, nameChanged)
|
||||
|
||||
redirect := fmt.Sprintf("/person/%s/edit?saved_message=%s", id, url.QueryEscape("Änderungen gespeichert."))
|
||||
return e.Redirect(http.StatusSeeOther, redirect)
|
||||
|
||||
Reference in New Issue
Block a user