Skip to content

Commit

Permalink
Remove cache_write_statements as it has no use case for now
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Apr 21, 2020
1 parent a79e954 commit 377fdba
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 37 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

### Bug fixes

* [ecto] Support `as` and `parent_as` from Ecto vv3.4.3+
* [repo] Support `cache_write_statements: :per_schema | :per_operation` at the Repo configuration to control how write queries are cached
* [ecto] Support `as` and `parent_as` from Ecto v3.4.3+

## v3.4.2 (2020-04-02)

Expand Down
3 changes: 1 addition & 2 deletions integration_test/myxql/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ 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,
cache_write_statements: :per_schema
show_sensitive_data_on_connection_error: true
)

defmodule Ecto.Integration.TestRepo do
Expand Down
3 changes: 1 addition & 2 deletions integration_test/pg/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ 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,
show_sensitive_data_on_connection_error: true,
cache_write_statements: :per_schema
show_sensitive_data_on_connection_error: true
)

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

defmodule Ecto.Integration.TestRepo do
Expand Down
9 changes: 1 addition & 8 deletions lib/ecto/adapters/myxql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ 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_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
itself.
* `:socket_options` - Specifies socket configuration
* `:show_sensitive_data_on_connection_error` - show connection data and
configuration whenever there is an error attempting to connect to the
Expand Down Expand Up @@ -231,9 +226,7 @@ defmodule Ecto.Adapters.MyXQL do
key = primary_key!(schema_meta, returning)
{fields, values} = :lists.unzip(params)
sql = @conn.insert(prefix, source, fields, [fields], on_conflict, [])

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

case Ecto.Adapters.SQL.query(adapter_meta, sql, values ++ query_params, opts) do
{:ok, %{num_rows: 1, last_insert_id: last_insert_id}} ->
Expand Down
5 changes: 0 additions & 5 deletions lib/ecto/adapters/postgres.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ 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_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
itself.
* `:connect_timeout` - The timeout for establishing new connections (default: 5000)
* `:prepare` - How to prepare queries, either `:named` to use named queries
or `:unnamed` to force unnamed queries (default: `:named`)
Expand Down
14 changes: 3 additions & 11 deletions lib/ecto/adapters/sql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,9 @@ defmodule Ecto.Adapters.SQL do
telemetry_prefix = Keyword.fetch!(config, :telemetry_prefix)
telemetry = {config[:repo], log, telemetry_prefix ++ [:query]}

{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_write_statements: cache_write_statements}
meta = %{telemetry: telemetry, sql: connection, opts: opts}
{:ok, connection.child_spec(config), meta}
end

Expand Down Expand Up @@ -490,21 +489,14 @@ defmodule Ecto.Adapters.SQL do

## Query

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

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

@doc false
def insert_all(adapter_meta, schema_meta, conn, header, rows, on_conflict, returning, opts) do
%{source: source, prefix: prefix} = schema_meta
{_, conflict_params, _} = on_conflict
{rows, params} = unzip_inserts(header, rows)
sql = conn.insert(prefix, source, header, rows, on_conflict, returning)

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

%{num_rows: num, rows: rows} =
query!(adapter_meta, sql, Enum.reverse(params) ++ conflict_params, opts)
Expand Down Expand Up @@ -633,7 +625,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_write_statements(adapter_meta, operation, source)
cache_statement = "ecto_#{operation}_#{source}"

case query(adapter_meta, sql, values, [cache_statement: cache_statement] ++ opts) do
{:ok, %{rows: nil, num_rows: 1}} ->
Expand Down
5 changes: 0 additions & 5 deletions lib/ecto/adapters/tds.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ 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_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
itself.
* `:show_sensitive_data_on_connection_error` - show connection data and
configuration whenever there is an error attempting to connect to the
database
Expand Down

0 comments on commit 377fdba

Please sign in to comment.