Commit 2360335a9d17bffd3deca402f16c96ac97ccafa1
1 parent
3ff8798a
Exists in
master
and in
2 other branches
with_scope doesn't always restore scope with Mongoid [skip ci]
Showing
1 changed file
with
6 additions
and
1 deletions
Show diff stats
lib/searchkick/relation_indexer.rb
... | ... | @@ -80,8 +80,13 @@ module Searchkick |
80 | 80 | klass = relation.klass |
81 | 81 | each_batch(relation, batch_size: batch_size) do |batch| |
82 | 82 | # prevent scope from affecting search_data as well as inline jobs |
83 | - klass.with_scope(nil) do | |
83 | + # note: Model.with_scope doesn't always restore scope, so use custom logic | |
84 | + previous_scope = Mongoid::Threaded.current_scope(klass) | |
85 | + begin | |
86 | + Mongoid::Threaded.set_current_scope(nil, klass) | |
84 | 87 | yield batch |
88 | + ensure | |
89 | + Mongoid::Threaded.set_current_scope(previous_scope, klass) | |
85 | 90 | end |
86 | 91 | end |
87 | 92 | end | ... | ... |