From 668bd5da0a77f9c4974ee9775ca91f2ab59a41b0 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 30 Dec 2021 20:19:35 -0600 Subject: CombineActivitiesAndObjects: add defaults, and missing indexes --- .../20211218181647_combine_activities_and_objects.exs | 12 ++++++++---- .../20211231013155_add_object_concurrent_indexes.exs | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 priv/repo/migrations/20211231013155_add_object_concurrent_indexes.exs diff --git a/priv/repo/migrations/20211218181647_combine_activities_and_objects.exs b/priv/repo/migrations/20211218181647_combine_activities_and_objects.exs index 153ac9718..749704cf1 100644 --- a/priv/repo/migrations/20211218181647_combine_activities_and_objects.exs +++ b/priv/repo/migrations/20211218181647_combine_activities_and_objects.exs @@ -7,9 +7,9 @@ defmodule Pleroma.Repo.Migrations.CombineActivitiesAndObjects do def up do # Add missing fields to objects table alter table(:objects) do - add(:local, :boolean) + add(:local, :boolean, null: false, default: true) add(:actor, :string) - add(:recipients, {:array, :string}) + add(:recipients, {:array, :string}, default: [])) end # Add missing indexes to objects @@ -18,11 +18,15 @@ defmodule Pleroma.Repo.Migrations.CombineActivitiesAndObjects do create_if_not_exists(index(:objects, [:recipients], using: :gin)) create_if_not_exists( - index(:objects, ["(data->'to')"], name: :activities_to_index, using: :gin) + index(:objects, ["(data->'to')"], name: :objects_to_index, using: :gin) ) create_if_not_exists( - index(:objects, ["(data->'cc')"], name: :activities_cc_index, using: :gin) + index(:objects, ["(data->'cc')"], name: :objects_cc_index, using: :gin) + ) + + create_if_not_exists( + index(:objects, ["(data->>'actor')", "inserted_at desc"], name: :objects_actor_index) ) # Some obscure Fediverse backends (WordPress, Juick) send a Create and a Note diff --git a/priv/repo/migrations/20211231013155_add_object_concurrent_indexes.exs b/priv/repo/migrations/20211231013155_add_object_concurrent_indexes.exs new file mode 100644 index 000000000..370d86733 --- /dev/null +++ b/priv/repo/migrations/20211231013155_add_object_concurrent_indexes.exs @@ -0,0 +1,14 @@ +defmodule Pleroma.Repo.Migrations.AddObjectConcurrentIndexes do + use Ecto.Migration + @disable_ddl_transaction true + + def change do + create( + index(:objects, ["activity_visibility(actor, recipients, data)", "id DESC NULLS LAST"], + name: :objects_visibility_index, + concurrently: true, + where: "data->>'type' = 'Create'" + ) + ) + end +end -- cgit v1.2.3