Skip to content

Commit

Permalink
Merge pull request #84 from mongoid/use-mongo-query-cache
Browse files Browse the repository at this point in the history
Feature: Use Mongo::QueryCache if available.
  • Loading branch information
johnnyshields authored Oct 24, 2023
2 parents d2d47c7 + eab859c commit 14a2edd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### 6.0.5 (Next)

* Your contribution here.
* [#84](https://github.com/mongoid/mongoid_orderable/pull/84): Feature: Use Mongo::QueryCache if available.

### 6.0.4 (2023/02/01)

Expand Down
6 changes: 3 additions & 3 deletions lib/mongoid/orderable/generators/position.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ def generate(field_name)
klass.class_eval <<~KLASS, __FILE__, __LINE__ + 1
def orderable_position(field = nil)
field ||= default_orderable_field
send "orderable_\#{field}_position"
send("orderable_\#{field}_position")
end
KLASS

generate_method("orderable_#{field_name}_position") do
send field_name
send(field_name)
end

generate_method("orderable_#{field_name}_position=") do |value|
send "#{field_name}=", value
send("#{field_name}=", value)
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/mongoid/orderable/handlers/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(doc)
end

def with_transaction(&block)
Mongoid::QueryCache.uncached do
query_cache.uncached do
if Thread.current[THREAD_KEY]
yield
else
Expand Down Expand Up @@ -65,6 +65,10 @@ def transaction_opts
def transaction_max_retries
doc.orderable_keys.map {|k| doc.class.orderable_configs.dig(k, :transaction_max_retries) }.compact.max
end

def query_cache
defined?(Mongo::QueryCache) ? Mongo::QueryCache : Mongoid::QueryCache
end
end
end
end
Expand Down

0 comments on commit 14a2edd

Please sign in to comment.