update forum as well

This commit is contained in:
byte[] 2019-11-17 22:39:47 -05:00
parent 91517b756b
commit 19b54f5f58

View file

@ -9,6 +9,7 @@ defmodule Philomena.Posts do
alias Philomena.Topics.Topic
alias Philomena.Posts.Post
alias Philomena.Forums.Forum
alias Philomena.Notifications
@doc """
@ -44,6 +45,10 @@ defmodule Philomena.Posts do
Topic
|> where(id: ^topic.id)
forum_query =
Forum
|> where(id: ^topic.forum_id)
Multi.new
|> Multi.run(:post, fn repo, _ ->
last_position =
@ -64,6 +69,12 @@ defmodule Philomena.Posts do
{:ok, count}
end)
|> Multi.run(:update_forum, fn repo, %{post: %{id: post_id}} ->
{count, nil} =
repo.update_all(forum_query, inc: [post_count: 1], set: [last_post_id: post_id])
{:ok, count}
end)
|> Repo.isolated_transaction(:serializable)
end