mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
Fix reindex concurrency
This commit is contained in:
parent
e69d3aca4e
commit
25bedd2aa1
1 changed files with 20 additions and 12 deletions
|
@ -201,13 +201,17 @@ defmodule PhilomenaQuery.Search do
|
|||
"""
|
||||
@spec reindex(queryable(), schema_module(), Batch.batch_options()) :: :ok
|
||||
def reindex(queryable, module, opts \\ []) do
|
||||
max_concurrency = Keyword.get(opts, :max_concurrency, 1)
|
||||
index = @policy.index_for(module)
|
||||
|
||||
queryable
|
||||
|> Batch.record_batches(opts)
|
||||
|> Enum.each(fn records ->
|
||||
|> Batch.query_batches(opts)
|
||||
|> Task.async_stream(
|
||||
fn query ->
|
||||
lines =
|
||||
Enum.flat_map(records, fn record ->
|
||||
query
|
||||
|> Repo.all()
|
||||
|> Enum.flat_map(fn record ->
|
||||
doc = index.as_json(record)
|
||||
|
||||
[
|
||||
|
@ -217,7 +221,11 @@ defmodule PhilomenaQuery.Search do
|
|||
end)
|
||||
|
||||
Api.bulk(@policy.opensearch_url(), lines)
|
||||
end)
|
||||
end,
|
||||
timeout: :infinity,
|
||||
max_concurrency: max_concurrency
|
||||
)
|
||||
|> Stream.run()
|
||||
end
|
||||
|
||||
@doc ~S"""
|
||||
|
|
Loading…
Reference in a new issue