From bd373de069b571b2124ab47dcb61ec48da071d53 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Mon, 31 Jan 2022 13:56:58 +0000 Subject: [PATCH] Fixes #3940 - dead lock on user update in high load environment. --- app/models/concerns/has_group_relation_definition.rb | 3 +-- db/migrate/20120101000001_create_base.rb | 1 + db/migrate/20220131135531_issue3940_add_index.rb | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20220131135531_issue3940_add_index.rb diff --git a/app/models/concerns/has_group_relation_definition.rb b/app/models/concerns/has_group_relation_definition.rb index 51426aebc..ac376751e 100644 --- a/app/models/concerns/has_group_relation_definition.rb +++ b/app/models/concerns/has_group_relation_definition.rb @@ -14,8 +14,7 @@ module HasGroupRelationDefinition validates :access, presence: true validate :validate_access - after_save :touch_related - after_destroy :touch_related + after_commit :touch_related end private diff --git a/db/migrate/20120101000001_create_base.rb b/db/migrate/20120101000001_create_base.rb index 6c5d8ce84..7b2125f82 100644 --- a/db/migrate/20120101000001_create_base.rb +++ b/db/migrate/20120101000001_create_base.rb @@ -178,6 +178,7 @@ class CreateBase < ActiveRecord::Migration[4.2] add_index :groups_users, [:user_id] add_index :groups_users, [:group_id] add_index :groups_users, [:access] + add_index :groups_users, %i[user_id group_id access] add_foreign_key :groups_users, :users add_foreign_key :groups_users, :groups diff --git a/db/migrate/20220131135531_issue3940_add_index.rb b/db/migrate/20220131135531_issue3940_add_index.rb new file mode 100644 index 000000000..aa5ec184f --- /dev/null +++ b/db/migrate/20220131135531_issue3940_add_index.rb @@ -0,0 +1,10 @@ +# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ + +class Issue3940AddIndex < ActiveRecord::Migration[6.0] + def change + # return if it's a new setup + return if !Setting.exists?(name: 'system_init_done') + + add_index :groups_users, %i[user_id group_id access] + end +end