Lock the topic while computing topic_position

This commit is contained in:
byte[] 2023-04-10 22:16:10 -04:00
parent 5e908e40f6
commit e2c94dda6c

View file

@ -57,11 +57,16 @@ defmodule Philomena.Posts do
Topic Topic
|> where(id: ^topic.id) |> where(id: ^topic.id)
topic_lock_query =
topic_query
|> lock("FOR UPDATE")
forum_query = forum_query =
Forum Forum
|> where(id: ^topic.forum_id) |> where(id: ^topic.forum_id)
Multi.new() Multi.new()
|> Multi.all(:topic_lock, topic_lock_query)
|> Multi.run(:post, fn repo, _ -> |> Multi.run(:post, fn repo, _ ->
last_position = last_position =
Post Post