culturecode_stagehand 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 778925f3540847fcf089ab3ffb65d6993362c59e
4
- data.tar.gz: 770602a0719fef798f82744b00e9c60dc33f6c24
3
+ metadata.gz: 3dab896a9f7c3dc73684d932a38b73dd622078d8
4
+ data.tar.gz: 5c6ed76e33a075d8fad38b75270c4d07302b4356
5
5
  SHA512:
6
- metadata.gz: fd85561ed53df15f0180ef0a42eaa17f01e6c904e6208aec47b87b9ba3fdd661285c1bb88e8d6d16916df38247ff399d9d8e371b34761526bd877ce724d65b22
7
- data.tar.gz: 1e0a9fe56efcf5fe0a65183cbc3d798c629c814d6be31bf3aa4fa637821fbe4e8d9c037c1fa302372da03910f61d8066afd1dce047e218b1be059ced4afc7486
6
+ metadata.gz: 952176cc2d5c7a0a62651071afc0f8c290c94787dc744b3390a8264b74f0e0171500f7c306c5fffffc7d0de9f306dc0a0b2a5d39cd2f57d5359f03d37f644716
7
+ data.tar.gz: 4d76928b54fc1f3937617d7042ff5f47b2b9f234f8436e6c533fd1622fa764e05d0d092e47e22778f7f7c6601c10239de51c541054f05ebe528de10a333c229f
@@ -40,26 +40,31 @@ ActiveRecord::Base.class_eval do
40
40
 
41
41
  # MULTITHREADED CONNECTION HANDLING
42
42
 
43
+ class_attribute :stagehand_threadsafe_connections
44
+ self.stagehand_threadsafe_connections = true
45
+
43
46
  # The original implementation of remove_connection uses @connection_specification_name, which is shared across Threads.
44
47
  # We need to pass in the connection that model in the current thread is using if we call remove_connection.
45
48
  def self.remove_connection(name = StagehandConnectionMap.get(self))
49
+ return super unless stagehand_threadsafe_connections
50
+
46
51
  StagehandConnectionMap.set(self, nil)
47
52
  super
48
53
  end
49
54
 
50
55
  def self.connection_specification_name=(connection_name)
56
+ return super unless stagehand_threadsafe_connections
57
+
51
58
  # ActiveRecord sets the connection pool to 'primary' by default, so we want to reuse that connection for staging
52
59
  # in order to avoid using a different connection pool after our first swap back to the staging connection.
53
60
  connection_name == 'primary' if connection_name == Stagehand::Configuration.staging_connection_name
54
61
 
55
62
  StagehandConnectionMap.set(self, connection_name)
56
-
57
- # We want to keep track of the @connection_specification_name as a fallback shared across threads in case we
58
- # haven't set the connection on more than one thread.
59
- super
60
63
  end
61
64
 
62
65
  def self.connection_specification_name
66
+ return super unless stagehand_threadsafe_connections
67
+
63
68
  StagehandConnectionMap.get(self) || super
64
69
  end
65
70
 
@@ -1,4 +1,5 @@
1
1
  require 'thread'
2
+ require 'stagehand/active_record_extensions'
2
3
 
3
4
  module Stagehand
4
5
  module Database
@@ -77,8 +78,6 @@ module Stagehand
77
78
  private
78
79
 
79
80
  def swap_connection(connection_name)
80
- raise ConnectionSwapDuringTransaction unless safe_to_swap_connection?
81
-
82
81
  cache = ActiveRecord::Base.connection_pool.query_cache_enabled
83
82
  ConnectionStack.push(connection_name.to_sym)
84
83
  ActiveRecord::Base.connection_specification_name = current_connection_name
@@ -91,10 +90,6 @@ module Stagehand
91
90
  ActiveRecord::Base.connection_pool.enable_query_cache! if cache
92
91
  end
93
92
 
94
- def safe_to_swap_connection?
95
- ActiveRecord::Base.connection.open_transactions == 0
96
- end
97
-
98
93
  def current_connection_name
99
94
  ConnectionStack.last
100
95
  end
@@ -111,6 +106,7 @@ module Stagehand
111
106
 
112
107
  class Probe < ActiveRecord::Base
113
108
  self.abstract_class = true
109
+ self.stagehand_threadsafe_connections = false # We don't want to track connection per-thread for Probes
114
110
 
115
111
  # We fake the class name so we can create a connection pool with the desired connection name instead of the name of the class
116
112
  def self.init_connection(connection_name)
@@ -166,8 +162,4 @@ module Stagehand
166
162
  end
167
163
  end
168
164
  end
169
-
170
- # EXCEPTIONS
171
-
172
- class ConnectionSwapDuringTransaction < StandardError; end
173
165
  end
@@ -1,3 +1,3 @@
1
1
  module Stagehand
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: culturecode_stagehand
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Jakobsen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-01-31 00:00:00.000000000 Z
12
+ date: 2019-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails