Skip to content

Commit cb78a5e

Browse files
committed
Make upsert atomic
1 parent 09c512b commit cb78a5e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

app/models/setting.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ def []=(key, value)
7474
if value.nil?
7575
where(var: dynamic_key).destroy_all
7676
else
77-
super(dynamic_key, value)
77+
# Use upsert for atomic insert/update to avoid race conditions
78+
upsert({ var: dynamic_key, value: value.to_yaml }, unique_by: :var)
79+
clear_cache
7880
end
7981
end
8082
end

0 commit comments

Comments
 (0)