Refactor Core things, including Ecto handling, ActivityPub & Transmogrifier modules

* Data doesn't need anymore to be converted to ActivityStream format to
be saved (this was taken from Pleroma and not at all a good idea here)
* Everything saved when creating an event is inserted into PostgreSQL in
a single transaction
This commit is contained in:
Thomas Citharel
2019-10-25 17:43:37 +02:00
parent 814cfbc8eb
commit cc820d6b63
69 changed files with 1881 additions and 1424 deletions

View File

@@ -1,12 +1,5 @@
defmodule Mobilizon.Storage.Repo.Migrations.AddEagerMaterializedViewForSearchingEvents do
use Ecto.Migration
import Ecto.Query
alias Mobilizon.Storage.Repo
alias Mobilizon.Service.Search
alias Mobilizon.Events.Event
require Logger
def up do
create table(:event_search, primary_key: false) do
@@ -28,35 +21,6 @@ defmodule Mobilizon.Storage.Repo.Migrations.AddEagerMaterializedViewForSearching
# to support updating CONCURRENTLY
create(unique_index("event_search", [:id]))
flush()
events =
Event
|> preload([e], :tags)
|> Repo.all()
nb_events = length(events)
IO.puts("\nStarting setting up search for #{nb_events} events, this can take a while…\n")
insert_search_event(events, nb_events)
end
defp insert_search_event([%Event{url: url} = event | events], nb_events) do
with {:ok, _} <- Search.insert_search_event(event) do
Logger.debug("Added event #{url} to the search")
else
{:error, res} ->
Logger.error("Error while adding event #{url} to the search: #{inspect(res)}")
end
ProgressBar.render(nb_events - length(events), nb_events)
insert_search_event(events, nb_events)
end
defp insert_search_event([], nb_events) do
IO.puts("\nFinished setting up search for #{nb_events} events!\n")
end
def down do

View File

@@ -0,0 +1,15 @@
defmodule Mobilizon.Storage.Repo.Migrations.MoveParticipantsStatsToEvent do
use Ecto.Migration
def up do
alter table(:events) do
add(:participant_stats, :map)
end
end
def down do
alter table(:events) do
remove(:participant_stats)
end
end
end

View File

@@ -0,0 +1,14 @@
defmodule Mobilizon.Storage.Repo.Migrations.AddTagsToComments do
use Ecto.Migration
def up do
create table(:comments_tags, primary_key: false) do
add(:comment_id, references(:comments, on_delete: :delete_all), primary_key: true)
add(:tag_id, references(:tags, on_delete: :nilify_all), primary_key: true)
end
end
def down do
drop(table(:comments_tags))
end
end

View File

@@ -0,0 +1,16 @@
defmodule Mobilizon.Storage.Repo.Migrations.AddMentionTables do
use Ecto.Migration
def change do
create table(:mentions) do
add(:silent, :boolean, default: false, null: false)
add(:actor_id, references(:actors, on_delete: :delete_all), null: false)
add(:event_id, references(:events, on_delete: :delete_all), null: true)
add(:comment_id, references(:comments, on_delete: :delete_all), null: true)
timestamps()
end
create(index(:mentions, [:actor_id]))
end
end

View File

@@ -0,0 +1,8 @@
defmodule Mobilizon.Storage.Repo.Migrations.AddUniqueIndexOnURLs do
use Ecto.Migration
def change do
create(unique_index(:events, [:url]))
create(unique_index(:comments, [:url]))
end
end