Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add batched SQL for insert/update operations
This introduce a new way of doing "migration" of data based on the operation table. Before, we simply executed the SQL query as the migration were run. Like for a "new" operation, we did an insert of a "transactions" row and an update to the "operations" table _for each entry in the synced file._ For a file containing 1000 keys, we did a total of 2000 SQL queries. After this commit, we only do 2 SQL queries (well 4 since we batch the SQL params by 500). By aggregating operation like {:update_all, operation.id, %{synced: true}}, we are able to batch the operations efficiently. This results in a much faster sync/add translations/correct/uncorrect operations.
- Loading branch information
Showing
22 changed files
with
290 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,11 @@ | ||
defmodule Movement.EctoMigrationHelper do | ||
alias Accent.Repo | ||
alias Movement.Migration | ||
def update(struct, params), do: {:update, {struct, params}} | ||
|
||
@doc """ | ||
Update given model by merging the existing parameters and the arguments. | ||
""" | ||
@spec update(model :: map, params :: map()) :: Migration.t() | ||
def update(model, params) do | ||
model | ||
|> model.__struct__.changeset(params) | ||
|> Repo.update!() | ||
end | ||
def insert(struct), do: {:insert, struct} | ||
|
||
def insert(model) do | ||
Repo.insert!(model) | ||
end | ||
def insert_all(schema, struct), do: {:insert_all, {schema, struct}} | ||
|
||
def update_all_dynamic(struct, types, fields, values), do: {:update_all_dynamic, {struct.__struct__, struct.id, types, fields, values}} | ||
|
||
def update_all(struct, params), do: {:update_all, {struct.__struct__, struct.id, params}} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
defmodule Movement.Migration do | ||
@type t :: map | ||
|
||
@callback call(atom, map) :: t() | ||
@callback call(atom, map) :: [t()] | t() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.