fix(auth): keep config persistence off the request lock

This commit is contained in:
ji ruo committed 2026-10-09 10:39:58 +08:00
1 parent 04c8c54ff8
commit ead58f0983
3 files changed
+206 -12

No files matched your search

+10 -2
View File
@@ -1,6 +1,9 @@
package db
import "database/sql"
import (
"context"
"database/sql"
)
// Settings is a tiny key-value store for global app config the UI toggles at
// runtime (e.g. traffic_capture). Missing keys fall back to caller defaults.
@@ -19,7 +22,12 @@ func (d *DB) GetSetting(key string) (value string, ok bool, err error) {
// SetSetting upserts a setting value.
func (d *DB) SetSetting(key, value string) error {
_, err := d.Exec(`
return d.SetSettingContext(context.Background(), key, value)
}
// SetSettingContext upserts a setting and respects cancellation or a deadline.
func (d *DB) SetSettingContext(ctx context.Context, key, value string) error {
_, err := d.ExecContext(ctx, `
INSERT INTO settings(key, value) VALUES ($1, $2)
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = now()`, key, value)
return err