discourse/app
Andrei Prigorshnev 84e13e9b1c
FIX: avoid race condition when setting user status (#19817)
We caught it in logs, race condition led to this error:

    ActiveRecord::RecordNotUnique 
    (PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "user_statuses_pkey"
    DETAIL:  Key (user_id)=(15) already exists.)


The reason the problem happened was that we were checking if a user has status and if not inserting status:

    if user_status
      ...
    else
      self.user_status = UserStatus.create!(status)
    end

The problem is that it's possible that another request will insert status just after we check if status exists and just before our request call `UserStatus.create!(status)`. Using `upsert` fixes the problem because under the hood `upsert` generates the only SQL request that uses "INSERT ... ON CONFLICT DO UPDATE". So we do everything in one SQL query, and that query takes care of resolving possible conflicts.
2023-02-06 18:56:28 +04:00
..
assets FIX: fix dragging in horizontal overflow component (#20018) 2023-02-06 09:51:41 -05:00
controllers FIX: Use / for start_url in webmanifest on non-subfolder installs (#20167) 2023-02-03 16:48:05 -03:00
helpers DEV: Prefer \A and \z over ^ and $ in regexes (#19936) 2023-01-20 12:52:49 -06:00
jobs FIX: Extend username updates to self-mentions (#20071) 2023-02-02 12:33:42 +00:00
mailers DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
models FIX: avoid race condition when setting user status (#19817) 2023-02-06 18:56:28 +04:00
serializers DEV: configurable custom sidebar sections (#20057) 2023-02-03 14:44:40 +11:00
services FIX: Category hashtags weren't always found for sub-sub-categories (#20156) 2023-02-03 12:17:52 +01:00
views DEV: use structured data in crawler-linkback-list for referencing only (#16237) 2023-01-30 08:26:55 +01:00