Skip to content

Commit 606c0bc

Browse files
committed
fix: Friendships not being properly deleted after account deletion
1 parent 4cd73eb commit 606c0bc

2 files changed

Lines changed: 42 additions & 11 deletions

File tree

‎lib/octocon/accounts.ex‎

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,7 @@ defmodule Octocon.Accounts do
1717
UserRegistry
1818
}
1919

20-
alias Octocon.Alters.{
21-
Alter,
22-
AlterWithProxies
23-
}
24-
25-
alias Octocon.Tags.{
26-
AlterTag,
27-
Tag
28-
}
29-
30-
alias Octocon.Polls.Poll
20+
alias Octocon.Alters.Alter
3121

3222
alias Octocon.Journals.{
3323
AlterJournalEntry,
@@ -819,6 +809,30 @@ defmodule Octocon.Accounts do
819809
where: gw.user_id == ^system_id
820810
)
821811
|> Repo.delete_all_regional({:user, {:system, system_id}})
812+
813+
from(
814+
f in Octocon.Friendships.Friendship,
815+
where: f.user_id == ^system_id
816+
)
817+
|> Repo.delete_all_global()
818+
819+
from(
820+
f in Octocon.Friendships.Friendship,
821+
where: f.friend_id == ^system_id
822+
)
823+
|> Repo.delete_all_global()
824+
825+
from(
826+
f in Octocon.Friendships.Request,
827+
where: f.from_id == ^system_id
828+
)
829+
|> Repo.delete_all_global()
830+
831+
from(
832+
f in Octocon.Friendships.Request,
833+
where: f.to_id == ^system_id
834+
)
835+
|> Repo.delete_all_global()
822836
end
823837

824838
@doc """
@@ -1059,5 +1073,7 @@ defmodule Octocon.Accounts do
10591073
end)
10601074

10611075
:ok
1076+
rescue
1077+
e -> {:error, e}
10621078
end
10631079
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule Octocon.Repo.Migrations.AddFriendshipsIndex do
2+
use Ecto.Migration
3+
4+
def change do
5+
create_index("global", "friendships", "friend_id")
6+
end
7+
8+
def create_index(keyspace, table, field) when is_binary(keyspace) and is_binary(table) and is_binary(field) do
9+
name = "#{table}_by_#{field}"
10+
11+
execute """
12+
CREATE INDEX IF NOT EXISTS #{name} ON #{keyspace}.#{table} (#{field})
13+
""", "DROP INDEX #{keyspace}.#{name}"
14+
end
15+
end

0 commit comments

Comments
 (0)