From ee1c4677eae192f9ddc07a91899c189d43447698 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Wed, 17 Jun 2020 17:41:45 +0200 Subject: [PATCH] Fixes #3087: Search taskbars cause DeadLocks. --- app/models/taskbar.rb | 1 + ...3806_issue_3087_search_taskbar_deadlock.rb | 14 +++++++ spec/models/taskbar_spec.rb | 39 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 db/migrate/20200617153806_issue_3087_search_taskbar_deadlock.rb diff --git a/app/models/taskbar.rb b/app/models/taskbar.rb index 2207a67e7..bf8ae393b 100644 --- a/app/models/taskbar.rb +++ b/app/models/taskbar.rb @@ -88,6 +88,7 @@ class Taskbar < ApplicationModel end def update_preferences_infos + return true if key == 'Search' return true if local_update # find other same open tasks diff --git a/db/migrate/20200617153806_issue_3087_search_taskbar_deadlock.rb b/db/migrate/20200617153806_issue_3087_search_taskbar_deadlock.rb new file mode 100644 index 000000000..0b52f7fc6 --- /dev/null +++ b/db/migrate/20200617153806_issue_3087_search_taskbar_deadlock.rb @@ -0,0 +1,14 @@ +class Issue3087SearchTaskbarDeadlock < ActiveRecord::Migration[5.2] + def change + Taskbar.where(key: 'Search').find_each do |taskbar| + next if taskbar.preferences.blank? + next if taskbar.preferences[:tasks].blank? + + taskbar.preferences.delete(:tasks) + + taskbar.save! + rescue => e + Rails.logger.error e + end + end +end diff --git a/spec/models/taskbar_spec.rb b/spec/models/taskbar_spec.rb index d6c2a6940..698060651 100644 --- a/spec/models/taskbar_spec.rb +++ b/spec/models/taskbar_spec.rb @@ -2,6 +2,45 @@ require 'rails_helper' RSpec.describe Taskbar do + context 'key = Search' do + + context 'multiple taskbars', current_user_id: 1 do + let(:key) { 'Search' } + let(:other_taskbar) { create(:taskbar, key: key) } + + describe '#create' do + + it "doesn't update other taskbar" do + expect do + create(:taskbar, key: key) + end.not_to change { other_taskbar.reload.updated_at } + end + end + + context 'existing taskbar' do + + subject(:taskbar) { create(:taskbar, key: key) } + + describe '#update' do + + it "doesn't update other taskbar" do + expect do + taskbar.update!(state: { foo: :bar }) + end.not_to change { other_taskbar.reload.updated_at } + end + end + + describe '#destroy' do + it "doesn't update other taskbar" do + expect do + taskbar.destroy! + end.not_to change { other_taskbar.reload.updated_at } + end + end + end + end + end + context 'single creation' do let(:taskbar) do