Skip to content

Commit b453bff

Browse files
committed
Inlining locked?
Since `locked?` and `arel_from_relation` overlaps, so just do `arel_from_relation` first and inline `locked?`.
1 parent 0aa832e commit b453bff

File tree

1 file changed

+5
-9
lines changed
  • activerecord/lib/active_record/connection_adapters/abstract

1 file changed

+5
-9
lines changed

activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,11 @@ def clear_query_cache
9494
end
9595

9696
def select_all(arel, name = nil, binds = [], preparable: nil)
97-
if @query_cache_enabled && !locked?(arel)
98-
arel = arel_from_relation(arel)
97+
arel = arel_from_relation(arel)
98+
99+
# If arel is locked this is a SELECT ... FOR UPDATE or somesuch.
100+
# Such queries should not be cached.
101+
if @query_cache_enabled && !(arel.respond_to?(:locked) && arel.locked)
99102
sql, binds, preparable = to_sql_and_binds(arel, binds, preparable)
100103

101104
cache_sql(sql, name, binds) { super(sql, name, binds, preparable: preparable) }
@@ -134,13 +137,6 @@ def cache_notification_info(sql, name, binds)
134137
}
135138
end
136139

137-
# If arel is locked this is a SELECT ... FOR UPDATE or somesuch. Such
138-
# queries should not be cached.
139-
def locked?(arel)
140-
arel = arel.arel if arel.is_a?(Relation)
141-
arel.respond_to?(:locked) && arel.locked
142-
end
143-
144140
def configure_query_cache!
145141
enable_query_cache! if pool.query_cache_enabled
146142
end

0 commit comments

Comments
 (0)