mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57: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
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue