mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
update forum as well
This commit is contained in:
parent
91517b756b
commit
19b54f5f58
1 changed files with 11 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue