Skip to content

Commit

Permalink
Rename cache_statement to cache_write_statements to avoid conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Apr 18, 2020
1 parent bbfc036 commit a34ebbd
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion integration_test/myxql/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ alias Ecto.Integration.TestRepo
Application.put_env(:ecto_sql, TestRepo,
url: Application.get_env(:ecto_sql, :mysql_test_url) <> "/ecto_test",
pool: Ecto.Adapters.SQL.Sandbox,
show_sensitive_data_on_connection_error: true
show_sensitive_data_on_connection_error: true,
cache_write_statements: :per_schema
)

defmodule Ecto.Integration.TestRepo do
Expand Down
4 changes: 3 additions & 1 deletion integration_test/pg/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ alias Ecto.Integration.TestRepo

Application.put_env(:ecto_sql, TestRepo,
url: Application.get_env(:ecto_sql, :pg_test_url) <> "/ecto_test",
pool: Ecto.Adapters.SQL.Sandbox
pool: Ecto.Adapters.SQL.Sandbox,
show_sensitive_data_on_connection_error: true,
cache_write_statements: :per_schema
)

defmodule Ecto.Integration.TestRepo do
Expand Down
4 changes: 3 additions & 1 deletion integration_test/tds/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ Application.put_env(
TestRepo,
url: Application.get_env(:ecto_sql, :tds_test_url) <> "/ecto_test",
pool: Ecto.Adapters.SQL.Sandbox,
set_allow_snapshot_isolation: :on
set_allow_snapshot_isolation: :on,
show_sensitive_data_on_connection_error: true,
cache_write_statements: :per_schema
)

defmodule Ecto.Integration.TestRepo do
Expand Down
4 changes: 2 additions & 2 deletions lib/ecto/adapters/myxql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule Ecto.Adapters.MyXQL do
This option is only used for `mix ecto.load` and `mix ecto.dump`,
via the `mysql` command. For more information, please check
[MySQL docs](https://dev.mysql.com/doc/en/connecting.html)
* `:cache_statement` - how Ecto should cache INSERT/UPDATE/DELETE statements.
* `:cache_write_statements` - how Ecto should cache INSERT/UPDATE/DELETE statements.
It defaults to `:per_schema` (one cache key is used for each schema) and
can be set to `:per_operation` (one cache key is use for each operation).
Note SELECTs use a more complete cache mechanism that considers the query
Expand Down Expand Up @@ -232,7 +232,7 @@ defmodule Ecto.Adapters.MyXQL do
{fields, values} = :lists.unzip(params)
sql = @conn.insert(prefix, source, fields, [fields], on_conflict, [])

cache_statement = "ecto_insert_#{source}"
cache_statement = Ecto.Adapters.SQL.cache_write_statements(adapter_meta, "insert", source)
opts = [{:cache_statement, cache_statement} | opts]

case Ecto.Adapters.SQL.query(adapter_meta, sql, values ++ query_params, opts) do
Expand Down
2 changes: 1 addition & 1 deletion lib/ecto/adapters/postgres.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Ecto.Adapters.Postgres do
* `:ssl` - Set to true if ssl should be used (default: false)
* `:ssl_opts` - A list of ssl options, see Erlang's `ssl` docs
* `:parameters` - Keyword list of connection parameters
* `:cache_statement` - how Ecto should cache INSERT/UPDATE/DELETE statements.
* `:cache_write_statements` - how Ecto should cache INSERT/UPDATE/DELETE statements.
It defaults to `:per_schema` (one cache key is used for each schema) and
can be set to `:per_operation` (one cache key is use for each operation).
Note SELECTs use a more complete cache mechanism that considers the query
Expand Down
13 changes: 7 additions & 6 deletions lib/ecto/adapters/sql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,10 @@ defmodule Ecto.Adapters.SQL do
telemetry_prefix = Keyword.fetch!(config, :telemetry_prefix)
telemetry = {config[:repo], log, telemetry_prefix ++ [:query]}

cache_statement = Keyword.get(config, :cache_statement, :per_schema)
{cache_write_statements, config} = Keyword.pop(config, :cache_write_statements, :per_schema)
config = adapter_config(config)
opts = Keyword.take(config, @pool_opts)
meta = %{telemetry: telemetry, sql: connection, opts: opts, cache_statement: cache_statement}
meta = %{telemetry: telemetry, sql: connection, opts: opts, cache_write_statements: cache_write_statements}
{:ok, connection.child_spec(config), meta}
end

Expand Down Expand Up @@ -490,10 +490,11 @@ defmodule Ecto.Adapters.SQL do

## Query

defp cache_statement(%{cache_statement: :per_schema}, operation, source),
@doc false
def cache_write_statements(%{cache_write_statements: :per_schema}, operation, source),
do: "ecto_#{operation}_#{source}"

defp cache_statement(%{cache_statement: :per_operation}, operation, _source),
def cache_write_statements(%{cache_write_statements: :per_operation}, operation, _source),
do: "ecto_#{operation}"

@doc false
Expand All @@ -503,7 +504,7 @@ defmodule Ecto.Adapters.SQL do
{rows, params} = unzip_inserts(header, rows)
sql = conn.insert(prefix, source, header, rows, on_conflict, returning)

opts = [{:cache_statement, cache_statement(adapter_meta, "insert_all", source)} | opts]
opts = [{:cache_statement, cache_write_statements(adapter_meta, "insert_all", source)} | opts]

%{num_rows: num, rows: rows} =
query!(adapter_meta, sql, Enum.reverse(params) ++ conflict_params, opts)
Expand Down Expand Up @@ -632,7 +633,7 @@ defmodule Ecto.Adapters.SQL do

@doc false
def struct(adapter_meta, conn, sql, operation, source, params, values, on_conflict, returning, opts) do
cache_statement = cache_statement(adapter_meta, operation, source)
cache_statement = cache_write_statements(adapter_meta, operation, source)

case query(adapter_meta, sql, values, [cache_statement: cache_statement] ++ opts) do
{:ok, %{rows: nil, num_rows: 1}} ->
Expand Down
2 changes: 1 addition & 1 deletion lib/ecto/adapters/tds.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Ecto.Adapters.Tds do
* `:pool` - The connection pool module, defaults to `DBConnection.ConnectionPool`
* `:ssl` - Set to true if ssl should be used (default: false)
* `:ssl_opts` - A list of ssl options, see Erlang's `ssl` docs
* `:cache_statement` - how Ecto should cache INSERT/UPDATE/DELETE statements.
* `:cache_write_statements` - how Ecto should cache INSERT/UPDATE/DELETE statements.
It defaults to `:per_schema` (one cache key is used for each schema) and
can be set to `:per_operation` (one cache key is use for each operation).
Note SELECTs use a more complete cache mechanism that considers the query
Expand Down

0 comments on commit a34ebbd

Please sign in to comment.