ruby on rails - Is there a good way to temporarily prevent ActiveRecord from performing queries? -
i have set of activerecord models pre-loading in order avoid n+1 issues. in order help process along, i'd able manual testing have (conceptually) blocks following:
# prepare info data = foo.includes(:bar, {baz: :quux}).find(27) activerecord.raise_error_if_any_queries_occur perform_some_work_with_data(data) activerecord.back_to_normal
this seems there should way it, haven't had luck. has else done this?
you can disconnect activerecord database , reconnect when finished:
data = foo.includes(:bar, {baz: :quux}).find(27) foo.connection.disconnect! perform_some_work_with_data(data) foo.connection.reconnect!
this raise error if tries run query against database while activerecord disconnected.
ruby-on-rails ruby activerecord
No comments:
Post a Comment