fix: back to at least part-parallism, except sqlite

This commit is contained in:
2026-04-25 19:24:51 +02:00
parent 7c73b984dc
commit 5c138d54b8
8 changed files with 278 additions and 100 deletions

View File

@@ -323,10 +323,22 @@ defmodule BDS.Desktop.ShellCommandsTest do
)
assert progressed.group_name == "Maintenance"
assert progressed.message =~ "Rebuilding post files"
assert String.contains?(progressed.message, "post")
assert wait_for_task(progressed.id, &(&1.status == :completed and &1.progress == 1.0), 5_000).status ==
:completed
tasks = wait_for_tasks_by_name([
"Rebuild Posts From Files",
"Rebuild Media From Files",
"Rebuild Scripts From Files",
"Rebuild Templates From Files",
"Rebuild Post Links",
"Regenerate Missing Thumbnails",
"Rebuild Embedding Index"
], &(&1.status == :completed), 20_000)
assert Enum.all?(tasks, &(&1.status == :completed))
end
test "reindex_text queues a tracked background task for the active project", %{project: project} do

View File

@@ -618,6 +618,68 @@ defmodule BDS.PostsTest do
refute BDS.Repo.get(BDS.Posts.Post, stale_post.id)
end
test "rebuild_posts_from_files batches search and embedding refresh after import", %{project: project} do
assert {:ok, _metadata} =
BDS.Metadata.update_project_metadata(project.id, %{semantic_similarity_enabled: true})
posts_dir = Path.join([BDS.Projects.project_data_dir(project), "posts", "2026", "04"])
File.mkdir_p!(posts_dir)
Enum.each(1..3, fn index ->
slug = "batched-post-#{index}"
File.write!(
Path.join(posts_dir, "#{slug}.md"),
[
"---",
"id: #{slug}",
"title: Batched Post #{index}",
"slug: #{slug}",
"status: published",
"language: en",
"createdAt: 1711843200",
"updatedAt: 1711929600",
"publishedAt: 1712016000",
"tags:",
"categories:",
"---",
"Body #{index}",
""
]
|> Enum.join("\n")
)
end)
handler_id = "posts-rebuild-batch-#{System.unique_integer([:positive])}"
:ok =
:telemetry.attach(
handler_id,
[:bds, :repo, :query],
&__MODULE__.handle_repo_query/4,
self()
)
on_exit(fn -> :telemetry.detach(handler_id) end)
assert {:ok, posts} = BDS.Posts.rebuild_posts_from_files(project.id)
assert length(posts) == 3
queries = drain_repo_queries([])
assert count_queries(queries, "settings") <= 12
assert count_queries(queries, "posts_fts") <= 4
assert {:ok, results} = BDS.Search.search_posts(project.id, "Batched Post", %{})
assert results.total == 3
assert {:ok, %{indexed: 3, total: 3}} = BDS.Embeddings.get_indexing_progress(project.id)
end
def handle_repo_query(_event, _measurements, metadata, owner_pid) do
send(owner_pid, {:repo_query, metadata.query || ""})
end
defp errors_on(changeset) do
Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
Regex.replace(~r"%{(\w+)}", message, fn _, key ->
@@ -625,4 +687,16 @@ defmodule BDS.PostsTest do
end)
end)
end
defp drain_repo_queries(acc) do
receive do
{:repo_query, query} -> drain_repo_queries([query | acc])
after
0 -> Enum.reverse(acc)
end
end
defp count_queries(queries, fragment) do
Enum.count(queries, &String.contains?(&1, fragment))
end
end