mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-25 14:34:33 +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.Topics.Topic
|
||||||
alias Philomena.Posts.Post
|
alias Philomena.Posts.Post
|
||||||
|
alias Philomena.Forums.Forum
|
||||||
alias Philomena.Notifications
|
alias Philomena.Notifications
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -44,6 +45,10 @@ defmodule Philomena.Posts do
|
||||||
Topic
|
Topic
|
||||||
|> where(id: ^topic.id)
|
|> where(id: ^topic.id)
|
||||||
|
|
||||||
|
forum_query =
|
||||||
|
Forum
|
||||||
|
|> where(id: ^topic.forum_id)
|
||||||
|
|
||||||
Multi.new
|
Multi.new
|
||||||
|> Multi.run(:post, fn repo, _ ->
|
|> Multi.run(:post, fn repo, _ ->
|
||||||
last_position =
|
last_position =
|
||||||
|
@ -64,6 +69,12 @@ defmodule Philomena.Posts do
|
||||||
|
|
||||||
{:ok, count}
|
{:ok, count}
|
||||||
end)
|
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)
|
|> Repo.isolated_transaction(:serializable)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue