mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
attempt non-atomic update for gallery ordering
This commit is contained in:
parent
723bfa213f
commit
bd401cf967
1 changed files with 16 additions and 8 deletions
|
@ -255,21 +255,29 @@ defmodule Philomena.Galleries do
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
id: interaction.id,
|
id: interaction.id,
|
||||||
gallery_id: interaction.gallery_id,
|
|
||||||
image_id: interaction.image_id,
|
|
||||||
position: interaction_positions[new_index]
|
position: interaction_positions[new_index]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
changes
|
||||||
|
|> Enum.map(fn change ->
|
||||||
|
id = Keyword.fetch!(change, :id)
|
||||||
|
change = Keyword.delete(change, :id)
|
||||||
|
|
||||||
|
Interaction
|
||||||
|
|> where([i], i.id == ^id)
|
||||||
|
|> Repo.update_all(set: change)
|
||||||
|
end)
|
||||||
|
|
||||||
# Do the update in a single statement
|
# Do the update in a single statement
|
||||||
Repo.insert_all(
|
# Repo.insert_all(
|
||||||
Interaction,
|
# Interaction,
|
||||||
changes,
|
# changes,
|
||||||
on_conflict: {:replace, [:position]},
|
# on_conflict: {:replace, [:position]},
|
||||||
conflict_target: [:id]
|
# conflict_target: [:id]
|
||||||
)
|
# )
|
||||||
|
|
||||||
# Now update all the associated images
|
# Now update all the associated images
|
||||||
Images.reindex_images(Map.keys(requested))
|
Images.reindex_images(Map.keys(requested))
|
||||||
|
|
Loading…
Reference in a new issue