d
This commit is contained in:
@@ -2736,6 +2736,12 @@ def register_url_with_local_library(
|
||||
if not storage_path:
|
||||
return False
|
||||
|
||||
# Optimization: Don't open DB if file isn't in library root
|
||||
try:
|
||||
path_obj.resolve().relative_to(Path(storage_path).resolve())
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
with API_folder_store(storage_path) as db:
|
||||
file_hash = db.get_file_hash(path_obj)
|
||||
if not file_hash:
|
||||
|
||||
@@ -668,50 +668,72 @@ class Add_File(Cmdlet):
|
||||
# This keeps output consistent and ensures @N selection works for multi-item ingests.
|
||||
if want_final_search_file and collected_payloads:
|
||||
try:
|
||||
hashes: List[str] = []
|
||||
for payload in collected_payloads:
|
||||
h = payload.get("hash") if isinstance(payload, dict) else None
|
||||
if isinstance(h, str) and len(h) == 64:
|
||||
hashes.append(h)
|
||||
# Deduplicate while preserving order
|
||||
seen: set[str] = set()
|
||||
hashes = [h for h in hashes if not (h in seen or seen.add(h))]
|
||||
|
||||
if use_steps and steps_started:
|
||||
progress.step("refreshing display")
|
||||
|
||||
refreshed_items = Add_File._try_emit_search_file_by_hashes(
|
||||
store=str(location),
|
||||
hash_values=hashes,
|
||||
config=config,
|
||||
store_instance=storage_registry,
|
||||
)
|
||||
debug(f"[add-file] Internal refresh returned refreshed_items count={len(refreshed_items) if refreshed_items else 0}")
|
||||
if not refreshed_items:
|
||||
# Fallback: at least show the add-file payloads as a display overlay
|
||||
# If this was a single-item ingest, render the detailed item display
|
||||
# directly from the payload and skip the internal search-file refresh.
|
||||
if len(collected_payloads) == 1:
|
||||
from SYS.result_table import ResultTable
|
||||
from SYS.rich_display import render_item_details_panel
|
||||
|
||||
# If this was a single-item ingest, render the detailed item display
|
||||
# directly from the payload to avoid DB refresh contention.
|
||||
detail_rendered = False
|
||||
if len(collected_payloads) == 1:
|
||||
# Stop the live pipeline progress UI before rendering the details panel.
|
||||
# This prevents the progress display from lingering on screen.
|
||||
try:
|
||||
live_progress = ctx.get_live_progress()
|
||||
except Exception:
|
||||
live_progress = None
|
||||
if live_progress is not None:
|
||||
try:
|
||||
from SYS.rich_display import render_item_details_panel
|
||||
|
||||
render_item_details_panel(collected_payloads[0])
|
||||
table = ResultTable("Result")
|
||||
table.add_result(collected_payloads[0])
|
||||
setattr(table, "_rendered_by_cmdlet", True)
|
||||
ctx.set_last_result_table_overlay(
|
||||
table,
|
||||
collected_payloads,
|
||||
subject=collected_payloads[0]
|
||||
)
|
||||
detail_rendered = True
|
||||
stage_ctx = ctx.get_stage_context()
|
||||
pipe_idx = getattr(stage_ctx, "pipe_index", None)
|
||||
if isinstance(pipe_idx, int):
|
||||
live_progress.finish_pipe(
|
||||
int(pipe_idx),
|
||||
force_complete=True
|
||||
)
|
||||
except Exception:
|
||||
detail_rendered = False
|
||||
pass
|
||||
try:
|
||||
live_progress.stop()
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if hasattr(ctx, "set_live_progress"):
|
||||
ctx.set_live_progress(None)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
render_item_details_panel(collected_payloads[0])
|
||||
table = ResultTable("Result")
|
||||
table.add_result(collected_payloads[0])
|
||||
setattr(table, "_rendered_by_cmdlet", True)
|
||||
ctx.set_last_result_table_overlay(
|
||||
table,
|
||||
collected_payloads,
|
||||
subject=collected_payloads[0]
|
||||
)
|
||||
else:
|
||||
hashes: List[str] = []
|
||||
for payload in collected_payloads:
|
||||
h = payload.get("hash") if isinstance(payload, dict) else None
|
||||
if isinstance(h, str) and len(h) == 64:
|
||||
hashes.append(h)
|
||||
# Deduplicate while preserving order
|
||||
seen: set[str] = set()
|
||||
hashes = [h for h in hashes if not (h in seen or seen.add(h))]
|
||||
|
||||
if use_steps and steps_started:
|
||||
progress.step("refreshing display")
|
||||
|
||||
refreshed_items = Add_File._try_emit_search_file_by_hashes(
|
||||
store=str(location),
|
||||
hash_values=hashes,
|
||||
config=config,
|
||||
store_instance=storage_registry,
|
||||
)
|
||||
debug(f"[add-file] Internal refresh returned refreshed_items count={len(refreshed_items) if refreshed_items else 0}")
|
||||
if not refreshed_items:
|
||||
# Fallback: at least show the add-file payloads as a display overlay
|
||||
from SYS.result_table import ResultTable
|
||||
|
||||
if not detail_rendered:
|
||||
table = ResultTable("Result")
|
||||
for payload in collected_payloads:
|
||||
table.add_result(payload)
|
||||
@@ -800,6 +822,16 @@ class Add_File(Cmdlet):
|
||||
table = ctx.get_last_result_table()
|
||||
items = ctx.get_last_result_items()
|
||||
if table is not None and items:
|
||||
# If we have a single item refresh, render it as a panel immediately
|
||||
# and suppress the table output from the CLI runner.
|
||||
if len(items) == 1:
|
||||
try:
|
||||
from SYS.rich_display import render_item_details_panel
|
||||
render_item_details_panel(items[0])
|
||||
setattr(table, "_rendered_by_cmdlet", True)
|
||||
except Exception as exc:
|
||||
debug(f"[add-file] Item details render failed: {exc}")
|
||||
|
||||
ctx.set_last_result_table_overlay(
|
||||
table,
|
||||
items,
|
||||
|
||||
@@ -239,7 +239,9 @@ class search_file(Cmdlet):
|
||||
pass
|
||||
|
||||
db = None
|
||||
if library_root:
|
||||
# Disable Folder DB usage for "external" searches when not using a folder store
|
||||
# db = None
|
||||
if library_root and False: # Disabled to prevent 'database is locked' errors during external searches
|
||||
try:
|
||||
from API.folder import API_folder_store
|
||||
|
||||
@@ -936,7 +938,17 @@ class search_file(Cmdlet):
|
||||
pass
|
||||
|
||||
if refresh_mode:
|
||||
ctx.set_last_result_table_preserve_history(table, results_list)
|
||||
# For internal refresh, use overlay mode to avoid adding to history
|
||||
try:
|
||||
# Parse out the store/hash context if possible
|
||||
subject_context = None
|
||||
if "hash:" in query:
|
||||
subject_hash = query.split("hash:")[1].split(",")[0].strip()
|
||||
subject_context = {"store": backend_to_search, "hash": subject_hash}
|
||||
|
||||
ctx.set_last_result_table_overlay(table, results_list, subject=subject_context)
|
||||
except Exception:
|
||||
ctx.set_last_result_table_preserve_history(table, results_list)
|
||||
else:
|
||||
ctx.set_last_result_table(table, results_list)
|
||||
db.append_worker_stdout(
|
||||
|
||||
Reference in New Issue
Block a user