Merge remote-tracking branch 'origin/develop' into feature/account-export
This commit is contained in:
commit
d2113428c0
37 changed files with 1883 additions and 1731 deletions
|
|
@ -0,0 +1,38 @@
|
|||
defmodule Pleroma.Repo.Migrations.RemoveUnreadConversationCountFromUser do
|
||||
use Ecto.Migration
|
||||
import Ecto.Query
|
||||
alias Pleroma.Repo
|
||||
|
||||
def up do
|
||||
alter table(:users) do
|
||||
remove_if_exists(:unread_conversation_count, :integer)
|
||||
end
|
||||
end
|
||||
|
||||
def down do
|
||||
alter table(:users) do
|
||||
add_if_not_exists(:unread_conversation_count, :integer, default: 0)
|
||||
end
|
||||
|
||||
flush()
|
||||
recalc_unread_conversation_count()
|
||||
end
|
||||
|
||||
defp recalc_unread_conversation_count do
|
||||
participations_subquery =
|
||||
from(
|
||||
p in "conversation_participations",
|
||||
where: p.read == false,
|
||||
group_by: p.user_id,
|
||||
select: %{user_id: p.user_id, unread_conversation_count: count(p.id)}
|
||||
)
|
||||
|
||||
from(
|
||||
u in "users",
|
||||
join: p in subquery(participations_subquery),
|
||||
on: p.user_id == u.id,
|
||||
update: [set: [unread_conversation_count: p.unread_conversation_count]]
|
||||
)
|
||||
|> Repo.update_all([])
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
defmodule Pleroma.Repo.Migrations.AddUnreadIndexToConversationParticipation do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create(
|
||||
index(:conversation_participations, [:user_id],
|
||||
where: "read = false",
|
||||
name: "unread_conversation_participation_count_index"
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue