use mutex to guard sqlite writes
This commit is contained in:
2
main.go
2
main.go
@@ -703,10 +703,12 @@ func updateSummary(ctx context.Context, state *state, opts updateSummaryOptions)
|
||||
|
||||
summary := result.Text()
|
||||
|
||||
state.dbMutex.Lock()
|
||||
_, err = state.db.ExecContext(ctx, "INSERT OR REPLACE INTO summaries (location, summary) VALUES (?, ?)", locKey, summary)
|
||||
if err != nil {
|
||||
slog.Warn("unable to cache generated weather summary to db", "location", locKey, "error", err)
|
||||
}
|
||||
state.dbMutex.Unlock()
|
||||
|
||||
state.summaries.Store(locKey, summary)
|
||||
|
||||
|
Reference in New Issue
Block a user