Skip to content

Commit

Permalink
Merge branch 'main' into rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
djmb authored Jan 4, 2024
2 parents c96708d + a025e33 commit 35ac938
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/solid_cache/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def disable_instrumentation(&block)
end

def with_shard(shard, &block)
if shard && shard != Record.current_shard
Record.connected_to(shard: shard, &block)
if shard && SolidCache.connects_to
connected_to(shard: shard, role: default_role, prevent_writes: false, &block)
else
block.call
end
Expand Down
2 changes: 1 addition & 1 deletion lib/solid_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def self.each_shard(&block)

if (shards = all_shards_config&.keys)
shards.each do |shard|
Record.connected_to(shard: shard, &block)
Record.with_shard(shard, &block)
end
else
yield
Expand Down
9 changes: 9 additions & 0 deletions test/unit/solid_cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ class SolidCacheTest < ActiveSupport::TestCase
end
end

test "each_shard uses the default role" do
role = ActiveRecord::Base.connected_to(role: :reading) { SolidCache.each_shard.map { SolidCache::Record.current_role } }
if ENV["NO_CONNECTS_TO"]
assert_equal [ :reading ], role
else
assert_equal [ :writing, :writing, :writing, :writing, :writing ], role
end
end

test "max key bytesize" do
cache = lookup_store(max_key_bytesize: 100)
assert_equal 100, cache.send(:normalize_key, SecureRandom.hex(200), {}).bytesize
Expand Down

0 comments on commit 35ac938

Please sign in to comment.