From 28a33f869b6282e409446f99527b7e2ae5c1594c Mon Sep 17 00:00:00 2001 From: Kenneth Date: Tue, 13 May 2025 00:52:16 +0100 Subject: [PATCH] use mutex to guard sqlite writes --- main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.go b/main.go index 14e2090..eb96e2b 100644 --- a/main.go +++ b/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)