feat: issue #25 implemented - cli
This commit is contained in:
@@ -120,7 +120,7 @@ defmodule BDS.Desktop.ShellCommands do
|
||||
"rebuild_embedding_index",
|
||||
"Rebuild Embedding Index",
|
||||
"Embeddings",
|
||||
fn report -> rebuild_embedding_index_work(project, report) end
|
||||
fn report -> Maintenance.rebuild_embedding_index(project.id, on_progress: report) end
|
||||
)
|
||||
end
|
||||
|
||||
@@ -221,7 +221,7 @@ defmodule BDS.Desktop.ShellCommands do
|
||||
defp dispatch("rebuild_database", project, _params) do
|
||||
group_id = task_group_id("rebuild_database")
|
||||
attrs = %{group_id: group_id, group_name: "Maintenance"}
|
||||
[first_step | remaining_steps] = rebuild_database_steps(project)
|
||||
[first_step | remaining_steps] = Maintenance.full_rebuild_steps(project.id)
|
||||
|
||||
{:ok, posts_task} =
|
||||
Tasks.submit_task(first_step.name, first_step.work, attrs)
|
||||
@@ -692,102 +692,6 @@ defmodule BDS.Desktop.ShellCommands do
|
||||
|> length() > 1
|
||||
end
|
||||
|
||||
defp rebuild_database_steps(project) do
|
||||
[
|
||||
%{
|
||||
name: "Rebuild Posts From Files",
|
||||
work: fn report ->
|
||||
{:ok, posts} =
|
||||
Maintenance.rebuild_from_filesystem(project.id, "post",
|
||||
on_progress: report,
|
||||
rebuild_embeddings: false
|
||||
)
|
||||
|
||||
report.(1.0, "Post rebuild complete")
|
||||
%{project_id: project.id, counts: %{posts: length(posts)}}
|
||||
end
|
||||
},
|
||||
%{
|
||||
name: "Rebuild Media From Files",
|
||||
work: fn report ->
|
||||
{:ok, media} =
|
||||
Maintenance.rebuild_from_filesystem(project.id, "media", on_progress: report)
|
||||
|
||||
report.(1.0, "Media rebuild complete")
|
||||
%{project_id: project.id, counts: %{media: length(media)}}
|
||||
end
|
||||
},
|
||||
%{
|
||||
name: "Rebuild Scripts From Files",
|
||||
work: fn report ->
|
||||
{:ok, scripts} =
|
||||
Maintenance.rebuild_from_filesystem(project.id, "script", on_progress: report)
|
||||
|
||||
report.(1.0, "Script rebuild complete")
|
||||
%{project_id: project.id, counts: %{scripts: length(scripts)}}
|
||||
end
|
||||
},
|
||||
%{
|
||||
name: "Rebuild Templates From Files",
|
||||
work: fn report ->
|
||||
{:ok, templates} =
|
||||
Maintenance.rebuild_from_filesystem(project.id, "template", on_progress: report)
|
||||
|
||||
report.(1.0, "Template rebuild complete")
|
||||
%{project_id: project.id, counts: %{templates: length(templates)}}
|
||||
end
|
||||
},
|
||||
%{
|
||||
name: "Rebuild Post Links",
|
||||
work: fn report ->
|
||||
:ok = Posts.rebuild_post_links(project.id, on_progress: report)
|
||||
report.(1.0, "Post links rebuilt")
|
||||
%{project_id: project.id}
|
||||
end
|
||||
},
|
||||
%{
|
||||
name: "Regenerate Missing Thumbnails",
|
||||
work: fn report ->
|
||||
result = BDS.Media.regenerate_missing_thumbnails(project.id, on_progress: report)
|
||||
report.(1.0, "Missing thumbnails regenerated")
|
||||
Map.put(result, :project_id, project.id)
|
||||
end
|
||||
},
|
||||
%{
|
||||
name: "Rebuild Embedding Index",
|
||||
work: fn report -> rebuild_embedding_index_work(project, report) end
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
defp rebuild_embedding_index_work(project, report) do
|
||||
case Embeddings.rebuild_project(project.id, on_progress: report) do
|
||||
{:ok, rebuilt_post_ids} ->
|
||||
report.(1.0, "Embedding index rebuilt")
|
||||
|
||||
%{
|
||||
project_id: project.id,
|
||||
rebuilt_post_ids: rebuilt_post_ids,
|
||||
rebuilt_count: length(rebuilt_post_ids)
|
||||
}
|
||||
|
||||
{:error, reason} ->
|
||||
{:error, embedding_error_message(reason)}
|
||||
end
|
||||
end
|
||||
|
||||
defp embedding_error_message(reason) do
|
||||
detail =
|
||||
case reason do
|
||||
message when is_binary(message) -> message
|
||||
{:embedding_backend_unavailable, _inner} -> "the embedding service did not start"
|
||||
other -> inspect(other)
|
||||
end
|
||||
|
||||
"Could not build the embedding index: #{detail}. The model is downloaded on first use, " <>
|
||||
"so check your internet connection — or turn off semantic similarity in Settings."
|
||||
end
|
||||
|
||||
defp run_rebuild_sequence(_group_id, _attrs, []), do: :ok
|
||||
|
||||
defp run_rebuild_sequence(group_id, attrs, [step | remaining_steps]) do
|
||||
|
||||
Reference in New Issue
Block a user