Browse Source

Fixes #3940 - dead lock on user update in high load environment.

Rolf Schmidt 3 years ago
parent
commit
bd373de069

+ 1 - 2
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

+ 1 - 0
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
 

+ 10 - 0
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