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
import Ecto.Query
@indices [
{Images, Image},
{Comments, Comment},
{Galleries, Gallery},
{Tags, Tag},
{Posts, Post},
{Filters, Filter}
]
@shortdoc "Destroys and recreates all Elasticsearch indices."
@requirements ["app.start"]
@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"
end
for {context, schema} <- [
{Images, Image},
{Comments, Comment},
{Galleries, Gallery},
{Tags, Tag},
{Posts, Post},
{Filters, Filter}
] do
Elasticsearch.delete_index!(schema)
Elasticsearch.create_index!(schema)
@indices
|> Enum.map(fn {context, schema} ->
Task.async(fn ->
Elasticsearch.delete_index!(schema)
Elasticsearch.create_index!(schema)
Elasticsearch.reindex(preload(schema, ^context.indexing_preloads()), schema)
end
Elasticsearch.reindex(preload(schema, ^context.indexing_preloads()), schema)
end)
end)
|> Task.await_many(:infinity)
# Reports are a bit special