diff options
author | minibikini <egor@kislitsyn.com> | 2020-10-30 11:18:55 +0000 |
---|---|---|
committer | minibikini <egor@kislitsyn.com> | 2020-10-30 11:18:55 +0000 |
commit | 1cc8e945064319014300de5880a326d1100bf43e (patch) | |
tree | 938600cf0605372a15fe0cd909f94c364e409c20 /priv | |
parent | 8542d2efee86131350736a9be96713551e01f6ed (diff) | |
parent | 131f3219e6b895139c5647cd2050dd22adce7139 (diff) | |
download | pleroma-1cc8e945064319014300de5880a326d1100bf43e.tar.gz pleroma-1cc8e945064319014300de5880a326d1100bf43e.zip |
Merge branch 'develop' into 'feature/local-only-scope'
# Conflicts:
# CHANGELOG.md
Diffstat (limited to 'priv')
-rw-r--r-- | priv/repo/migrations/20200831114918_remove_unread_conversation_count_from_user.exs | 38 | ||||
-rw-r--r-- | priv/repo/migrations/20200831115854_add_unread_index_to_conversation_participation.exs | 12 |
2 files changed, 50 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200831114918_remove_unread_conversation_count_from_user.exs b/priv/repo/migrations/20200831114918_remove_unread_conversation_count_from_user.exs new file mode 100644 index 000000000..b7bdb9166 --- /dev/null +++ b/priv/repo/migrations/20200831114918_remove_unread_conversation_count_from_user.exs @@ -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 diff --git a/priv/repo/migrations/20200831115854_add_unread_index_to_conversation_participation.exs b/priv/repo/migrations/20200831115854_add_unread_index_to_conversation_participation.exs new file mode 100644 index 000000000..68771c655 --- /dev/null +++ b/priv/repo/migrations/20200831115854_add_unread_index_to_conversation_participation.exs @@ -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 |