forked from AkkomaGang/akkoma
Optimize conversation fetching.
This commit is contained in:
parent
1bc58230ee
commit
07b694814e
2 changed files with 9 additions and 1 deletions
|
@ -96,7 +96,7 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru
|
||||||
|
|
||||||
def fetch_activities_for_context(context) do
|
def fetch_activities_for_context(context) do
|
||||||
query = from activity in Activity,
|
query = from activity in Activity,
|
||||||
where: fragment("? @> ?", activity.data, ^%{ type: "Create", context: context }),
|
where: fragment("?->>'type' = ? and ?->>'context' = ?", activity.data, "Create", activity.data, ^context),
|
||||||
order_by: [desc: :inserted_at]
|
order_by: [desc: :inserted_at]
|
||||||
Repo.all(query)
|
Repo.all(query)
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.AddContextIndex do
|
||||||
|
use Ecto.Migration
|
||||||
|
@disable_ddl_transaction true
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create index(:activities, ["(data->>'type')", "(data->>'context')"], name: :activities_context_index, concurrently: true)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue