panda_pal 5.16.2 → 5.16.3
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 +4 -4
- data/config/initializers/apartment.rb +45 -68
- data/lib/panda_pal/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2c0409f3edd41806fcd606b52eb0c6441c43dac7b9e1eeb89c1871b6e08525f
|
4
|
+
data.tar.gz: 14b3313348391ab1c364ee9bb404af319bf93b831fc5bd552059faf41a179b71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2c460dd7ac5ff05da55ef6db233f0d266983927e6a295b469d1d19002ea833b26479c5b7db53fb6306761afc683bf3494fc07c63f1ac401f736d73ad803248b
|
7
|
+
data.tar.gz: bcccc2e5ad50d546f3258e513118e97a37f8104901436b3b3920d64986ad83159034a905cce7ded7b81529989d16d8151f0583ec7b273732e2d38be443a6dc8e
|
@@ -250,94 +250,71 @@ module PandaPal::Plugins::ApartmentCache
|
|
250
250
|
end
|
251
251
|
ActiveSupport::Cache::Store.send(:prepend, PandaPal::Plugins::ApartmentCache)
|
252
252
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
@tenant = name
|
258
|
-
end
|
259
|
-
|
260
|
-
def tenant
|
261
|
-
@tenant || 'public'
|
262
|
-
end
|
253
|
+
ActiveSupport.on_load(:action_cable) do
|
254
|
+
ActionCable::Connection::Base.module_eval do
|
255
|
+
def tenant=(name)
|
256
|
+
@tenant = name
|
263
257
|
end
|
264
|
-
end
|
265
258
|
|
266
|
-
|
267
|
-
|
268
|
-
module Channel
|
269
|
-
class Base
|
270
|
-
def self.broadcasting_for(model)
|
271
|
-
# Rails 5 #stream_for passes #channel_name as part of model. Rails 6 doesn't and includes it via #broadcasting_for.
|
272
|
-
model = [channel_name, model] unless model.is_a?(Array)
|
273
|
-
serialize_broadcasting([ Apartment::Tenant.current, model ])
|
274
|
-
end
|
275
|
-
|
276
|
-
def self.serialize_broadcasting(object)
|
277
|
-
case
|
278
|
-
when object.is_a?(Array)
|
279
|
-
object.map { |m| serialize_broadcasting(m) }.join(":")
|
280
|
-
when object.respond_to?(:to_gid_param)
|
281
|
-
object.to_gid_param
|
282
|
-
else
|
283
|
-
object.to_param
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
end
|
259
|
+
def tenant
|
260
|
+
@tenant || 'public'
|
288
261
|
end
|
262
|
+
end
|
289
263
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
264
|
+
# Include the Current Tenant in any broadcastings
|
265
|
+
if Rails.version >= '6.0'
|
266
|
+
ActionCable::Channel::Base.define_singleton_method(:broadcasting_for) do |*args|
|
267
|
+
cconn = ActionCable.server.worker_pool.connection
|
268
|
+
items = [cconn&.tenant || Apartment::Tenant.current, channel_name, *args]
|
269
|
+
serialize_broadcasting(items)
|
296
270
|
end
|
297
271
|
else
|
298
272
|
module ActionCable
|
299
273
|
module Channel
|
300
274
|
class Base
|
301
|
-
def
|
302
|
-
|
303
|
-
items = [cconn&.tenant || Apartment::Tenant.current, channel_name, *args]
|
304
|
-
serialize_broadcasting(items)
|
275
|
+
def broadcasting_for(model)
|
276
|
+
super([ Apartment::Tenant.current, model ])
|
305
277
|
end
|
306
278
|
end
|
307
279
|
end
|
308
280
|
end
|
281
|
+
end
|
309
282
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
283
|
+
# Lazily switch any worker threads to the correct tenant when they are working
|
284
|
+
# Actively calling `switch_tenant` for checks out a DB connection and calls `SET search_path`.
|
285
|
+
# The message processing may not interface with the DB, so this would be a huge waste.
|
286
|
+
# Instead, we ensure that the thread will trigger a :checkout if it needs a connection,
|
287
|
+
# at which time we hack-in the correct tenant/schema.
|
288
|
+
|
289
|
+
ActionCable::Server::Worker.set_callback :work, :around do |_, blk|
|
290
|
+
# Bit of a hack, but ensures the adapter is initialized (since such may incur DB calls (requiring a connection)
|
291
|
+
# which would then cause `checkout` to recurse)
|
292
|
+
Apartment::Tenant.adapter
|
293
|
+
|
294
|
+
# If the current thread already has a connection checked out, release it back to the pool so that the later after_checkout
|
295
|
+
# callback can set the schema properly.
|
296
|
+
pool = Apartment.connection_class.connection_pool
|
297
|
+
pool.release_connection if pool.active_connection?
|
298
|
+
|
299
|
+
Thread.current[:cable_tenant] = connection.tenant
|
300
|
+
blk.call
|
301
|
+
ensure
|
302
|
+
Thread.current[:cable_tenant] = nil
|
303
|
+
end
|
317
304
|
|
305
|
+
ActiveSupport.on_load(:active_record) do
|
318
306
|
if Apartment::Tenant.adapter.is_a?(Apartment::Adapters::PostgresqlSchemaAdapter)
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
adapter = Apartment::Tenant.adapter
|
327
|
-
# Apartment::Tenant.switch!(ct)
|
328
|
-
Thread.current[:cable_tenant] = ct
|
329
|
-
adapter.instance_variable_set(:@current, ct)
|
330
|
-
conn.schema_search_path = adapter.send :full_search_path
|
331
|
-
end
|
332
|
-
end
|
307
|
+
ActiveRecord::Base.connection.class.set_callback :checkout, :after do |conn|
|
308
|
+
next unless conn.pool == Apartment.connection_class.connection_pool
|
309
|
+
|
310
|
+
if (ct = Thread.current[:cable_tenant]).present?
|
311
|
+
adapter = Apartment::Tenant.adapter
|
312
|
+
adapter.instance_variable_set(:@current, ct)
|
313
|
+
conn.schema_search_path = adapter.send :full_search_path
|
333
314
|
end
|
334
315
|
end
|
335
|
-
|
336
|
-
ActiveRecord::ConnectionAdapters::ConnectionPool.prepend(ApartmentConnPoolMixin)
|
337
316
|
end
|
338
317
|
end
|
339
|
-
|
340
|
-
ActionCable::Connection::Base.prepend(PandaPal::Plugins::ActionCableApartment::Connection)
|
341
318
|
end
|
342
319
|
|
343
320
|
if defined?(Delayed)
|
data/lib/panda_pal/version.rb
CHANGED