discourse/app/models
Andrei Prigorshnev ded6aed15e
FIX: avoid race condition when setting user status (#19817) (#20182)
This is a backport of 84e13e9.

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 20:32:45 +04:00
..
concerns DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
about.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
admin_dashboard_data.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
admin_dashboard_general_data.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
admin_dashboard_index_data.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
allowed_pm_user.rb
anonymous_user.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
api_key_scope.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
api_key.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
application_request.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
associated_group.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
auto_track_duration_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
backup_draft_post.rb
backup_draft_topic.rb
backup_file.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
backup_location_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
backup_metadata.rb
badge_grouping.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
badge_type.rb
badge.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
base_font_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
bookmark.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
category_and_topic_lists.rb
category_custom_field.rb
category_featured_topic.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
category_group.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
category_list.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
category_page_style.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
category_required_tag_group.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
category_search_data.rb
category_tag_group.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
category_tag_stat.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
category_tag.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
category_user.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
category.rb FIX: deleted misconfigured embeddable hosts (#19833) 2023-01-25 13:48:49 +02:00
child_theme.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
color_scheme_color.rb
color_scheme_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
color_scheme.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
custom_emoji.rb FEATURE: Create upload_references table (#16146) 2022-06-09 09:24:30 +10:00
developer.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
digest_email_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
directory_column.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
directory_item.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
discourse_connect.rb FIX: skip email if blank while syncing SSO attributes. (#19939) 2023-01-25 13:48:49 +02:00
discourse_version_check.rb
dismissed_topic_user.rb
do_not_disturb_timing.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
draft_sequence.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
draft.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
email_change_request.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
email_level_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
email_log.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
email_style.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
email_token.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
embeddable_host.rb SECURITY: Remove bypass for base_url 2023-01-25 13:53:22 +02:00
embedding.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
emoji_set_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
emoji.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
external_upload_stub.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
given_daily_like.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
global_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
group_archived_message.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
group_associated_group.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
group_category_notification_default.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
group_custom_field.rb
group_history.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
group_manager.rb
group_mention.rb
group_request.rb SECURITY: Limit the character count of group membership requests 2023-01-25 13:53:07 +02:00
group_tag_notification_default.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
group_user.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
group.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
ignored_user.rb
imap_sync_log.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
incoming_domain.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
incoming_email.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
incoming_link.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
incoming_links_report.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
incoming_referer.rb
invite_redeemer.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
invite.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
invited_group.rb
invited_user.rb
javascript_cache.rb DEV: Introduce minification and source maps for Theme JS (#18646) 2022-10-18 18:20:10 +01:00
like_notification_frequency_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
linked_topic.rb
locale_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
mailing_list_mode_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
muted_user.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
navigation_menu_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
new_topic_duration_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
notification_level_when_replying_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
notification.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
oauth2_user_info.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
onceoff_log.rb
optimized_image.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
permalink.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
plugin_store_row.rb
plugin_store.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
post_action_type.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
post_action.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
post_analyzer.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
post_custom_field.rb DEV: Drop old hotlinked image data from post_custom_fields (#16594) 2022-05-12 15:34:35 +01:00
post_detail.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
post_hotlinked_media.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
post_mover.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
post_reply_key.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
post_reply.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
post_revision.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
post_search_data.rb
post_stat.rb
post_timing.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
post_upload.rb
post.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
previous_replies_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
private_message_topic_tracking_state.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
published_page.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
push_subscription.rb
quoted_post.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
remote_theme.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
remove_muted_tags_from_latest_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
report.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
reviewable_claimed_topic.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
reviewable_flagged_post.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
reviewable_history.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
reviewable_post.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
reviewable_priority_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
reviewable_queued_post.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
reviewable_score.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
reviewable_sensitivity_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
reviewable_user.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
reviewable.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
s3_region_site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
screened_email.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
screened_ip_address.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
screened_url.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
search_log.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
shared_draft.rb
shelved_notification.rb
sidebar_section_link.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
single_sign_on_record.rb
site_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
site.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
sitemap.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
skipped_email_log.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
slug_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
stylesheet_cache.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
tag_group_membership.rb
tag_group_permission.rb
tag_group.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
tag_search_data.rb
tag_user.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
tag.rb SECURITY: Default tags to show count of topics in unrestricted categories (#19929) 2023-01-20 11:59:37 +08:00
theme_field.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
theme_modifier_set.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
theme_setting.rb FEATURE: Create upload_references table (#16146) 2022-06-09 09:24:30 +10:00
theme_translation_override.rb DEV: Use the theme cache helper for settings 2022-02-21 09:45:14 +00:00
theme.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
top_lists.rb
top_menu_item.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
top_topic.rb FIX: Prevent concurrent updates to top_topics (#19854) 2023-01-25 13:48:49 +02:00
topic_allowed_group.rb
topic_allowed_user.rb
topic_converter.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_custom_field.rb
topic_embed.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_featured_users.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_group.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_invite.rb
topic_link_click.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_link.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_list.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_notifier.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_participants_summary.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_poster.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_posters_summary.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_search_data.rb
topic_tag.rb SECURITY: Default tags to show count of topics in unrestricted categories (#19929) 2023-01-20 11:59:37 +08:00
topic_thumbnail.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_timer.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_tracking_state.rb FIX: Regression in TopicTrackingState MessageBus message scope. (#19835) (#19837) 2023-01-12 08:52:02 +08:00
topic_user.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic_view_item.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
topic.rb SECURITY: Default tags to show count of topics in unrestricted categories (#19929) 2023-01-20 11:59:37 +08:00
translation_override.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
trust_level_and_staff_and_disabled_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
trust_level_and_staff_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
trust_level_setting.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
trust_level3_requirements.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
unsubscribe_key.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
upload_reference.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
upload.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_action.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_api_key_scope.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_api_key.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_archived_message.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_associated_account.rb
user_associated_group.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_auth_token_log.rb
user_auth_token.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_avatar.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_badge.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_badges.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_bookmark_list.rb FIX: Return next bookmarks page only if it exists (#18139) 2022-09-01 13:04:00 +03:00
user_custom_field.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_email.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_export.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_field_option.rb
user_field.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_history.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_ip_address_history.rb
user_notification_schedule.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_open_id.rb
user_option.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_profile_view.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_profile.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_search_data.rb
user_search.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_second_factor.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_security_key.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_stat.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_status.rb FEATURE: auto remove user status after predefined period (#17236) 2022-07-05 19:12:22 +04:00
user_summary.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_upload.rb
user_visit.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_warning.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user.rb FIX: avoid race condition when setting user status (#19817) (#20182) 2023-02-06 20:32:45 +04:00
username_validator.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
watched_word.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
web_crawler_request.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
web_hook_event_type.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
web_hook_event.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
web_hook.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00