Skip to content

Commit cf3a5b7

Browse files
authored
chore: accept a counter option in prepare_query/3 (#4714)
1 parent a9376cc commit cf3a5b7

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

lib/ecto/adapter/queryable.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@ defmodule Ecto.Adapter.Queryable do
104104
def prepare_query(operation, repo_name_or_pid, queryable, opts \\ []) do
105105
%{adapter: adapter, cache: cache} = Ecto.Repo.Registry.lookup(repo_name_or_pid)
106106

107+
counter = Keyword.get(opts, :counter, 0)
107108
query_cache? = Keyword.get(opts, :query_cache, true)
108109

109110
{_meta, prepared, _cast_params, dump_params} =
110111
queryable
111112
|> Ecto.Queryable.to_query()
112113
|> Ecto.Query.Planner.ensure_select(operation == :all)
113-
|> Ecto.Query.Planner.query(operation, cache, adapter, 0, query_cache?)
114+
|> Ecto.Query.Planner.query(operation, cache, adapter, counter, query_cache?)
114115

115116
{prepared, dump_params}
116117
end

lib/ecto/query/planner.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ defmodule Ecto.Query.Planner do
136136
def query(query, operation, cache, adapter, counter, query_cache?) do
137137
{query, params, key} = plan(query, operation, adapter)
138138
{cast_params, dump_params} = Enum.unzip(params)
139-
key = if query_cache?, do: key, else: :nocache
139+
key = if query_cache? and key != :nocache, do: {key, counter}, else: :nocache
140140
query_with_cache(key, query, operation, cache, adapter, counter, cast_params, dump_params)
141141
end
142142

0 commit comments

Comments
 (0)