mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 05:37:59 +01:00
concurrent reindexing for faster dev startup
This commit is contained in:
parent
724a2590fa
commit
c385771ecb
1 changed files with 18 additions and 12 deletions
|
@ -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
|
||||
@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
|
||||
end)
|
||||
end)
|
||||
|> Task.await_many(:infinity)
|
||||
|
||||
# Reports are a bit special
|
||||
|
||||
|
|
Loading…
Reference in a new issue