concurrent reindexing for faster dev startup

This commit is contained in:
byte[] 2021-04-01 11:16:47 -04:00
parent 724a2590fa
commit c385771ecb

View file

@ -18,6 +18,15 @@ defmodule Mix.Tasks.ReindexAll do
alias Philomena.Repo alias Philomena.Repo
import Ecto.Query import Ecto.Query
@indices [
{Images, Image},
{Comments, Comment},
{Galleries, Gallery},
{Tags, Tag},
{Posts, Post},
{Filters, Filter}
]
@shortdoc "Destroys and recreates all Elasticsearch indices." @shortdoc "Destroys and recreates all Elasticsearch indices."
@requirements ["app.start"] @requirements ["app.start"]
@impl Mix.Task @impl Mix.Task
@ -26,19 +35,16 @@ defmodule Mix.Tasks.ReindexAll do
raise "do not run this task unless you know what you're doing" raise "do not run this task unless you know what you're doing"
end end
for {context, schema} <- [ @indices
{Images, Image}, |> Enum.map(fn {context, schema} ->
{Comments, Comment}, Task.async(fn ->
{Galleries, Gallery},
{Tags, Tag},
{Posts, Post},
{Filters, Filter}
] do
Elasticsearch.delete_index!(schema) Elasticsearch.delete_index!(schema)
Elasticsearch.create_index!(schema) Elasticsearch.create_index!(schema)
Elasticsearch.reindex(preload(schema, ^context.indexing_preloads()), schema) Elasticsearch.reindex(preload(schema, ^context.indexing_preloads()), schema)
end end)
end)
|> Task.await_many(:infinity)
# Reports are a bit special # Reports are a bit special