summaryrefslogtreecommitdiff
path: root/lib/gitlab/patch
diff options
context:
space:
mode:
authorHeinrich Lee Yu <heinrich@gitlab.com>2019-04-26 23:49:19 +0800
committerHeinrich Lee Yu <heinrich@gitlab.com>2019-07-12 10:39:14 +0800
commitd4a919679a1eb5d3e2aaed4b920e6027d2482971 (patch)
treecdaaeb66e7de69a71994e08dd65478cab364fa24 /lib/gitlab/patch
parentecffca5d92353d55aaf8f984737fa617782310e0 (diff)
downloadgitlab-ce-d4a919679a1eb5d3e2aaed4b920e6027d2482971.tar.gz
Use transactions in JS feature specsjs-specs-transactions
Uses Rails transactional tests instead of DatabaseCleaner transaction strategy because that doesn't work with JS tests
Diffstat (limited to 'lib/gitlab/patch')
-rw-r--r--lib/gitlab/patch/active_record_query_cache.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/gitlab/patch/active_record_query_cache.rb b/lib/gitlab/patch/active_record_query_cache.rb
new file mode 100644
index 00000000000..71d66bdbe02
--- /dev/null
+++ b/lib/gitlab/patch/active_record_query_cache.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+# Fixes a bug where the query cache isn't aware of the shared
+# ActiveRecord connection used in tests
+# https://github.com/rails/rails/issues/36587
+
+# To be removed with https://gitlab.com/gitlab-org/gitlab-ce/issues/64413
+
+module Gitlab
+ module Patch
+ module ActiveRecordQueryCache
+ # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ def enable_query_cache!
+ @query_cache_enabled[connection_cache_key(current_thread)] = true
+ connection.enable_query_cache! if active_connection?
+ end
+
+ def disable_query_cache!
+ @query_cache_enabled.delete connection_cache_key(current_thread)
+ connection.disable_query_cache! if active_connection?
+ end
+
+ def query_cache_enabled
+ @query_cache_enabled[connection_cache_key(current_thread)]
+ end
+
+ def active_connection?
+ @thread_cached_conns[connection_cache_key(current_thread)]
+ end
+
+ private
+
+ def current_thread
+ @lock_thread || Thread.current
+ end
+ # rubocop:enable Gitlab/ModuleWithInstanceVariables
+ end
+ end
+end