This commit is contained in:
2026-01-17 21:32:44 -08:00
parent 193fa5aec3
commit 3f874af54a
4 changed files with 329 additions and 112 deletions

View File

@@ -21,7 +21,7 @@ from contextlib import contextmanager
from datetime import datetime
from pathlib import Path, PurePosixPath
from threading import RLock
from typing import Optional, Dict, Any, List, Tuple, Set
from typing import Optional, Dict, Any, List, Tuple, Set, Sequence
from SYS.utils import sha256_file, expand_path
from SYS.logger import debug as _debug
@@ -3001,6 +3001,47 @@ class DatabaseAPI:
)
return rows
def get_files_by_url_like_any(
self,
like_patterns: Sequence[str],
limit: Optional[int] = None,
) -> List[tuple]:
"""Get files whose URL metadata matches any of the provided LIKE patterns.
Returns (hash, file_path, size, ext, url) tuples.
"""
patterns = [str(p or "").strip() for p in (like_patterns or [])]
patterns = [p for p in patterns if p]
if not patterns:
return []
mm_debug(
f"[folder-db] get_files_by_url_like_any start: patterns={len(patterns)} limit={limit or 10000}"
)
cursor = self.get_cursor()
where_or = " OR ".join(["LOWER(m.url) LIKE ?"] * len(patterns))
query = f"""
SELECT f.hash, f.file_path,
COALESCE((SELECT size FROM metadata WHERE hash = f.hash), 0) as size,
COALESCE((SELECT ext FROM metadata WHERE hash = f.hash), '') as ext,
COALESCE(m.url, '') as url
FROM file f
JOIN metadata m ON f.hash = m.hash
WHERE m.url IS NOT NULL
AND ({where_or})
ORDER BY f.file_path
LIMIT ?
"""
cursor.execute(
query,
(*[p.lower() for p in patterns], limit or 10000),
)
rows = cursor.fetchall()
mm_debug(
f"[folder-db] get_files_by_url_like_any done: {len(rows)} row(s)"
)
return rows
def get_file_metadata(self,
file_hashes: Set[str],
limit: Optional[int] = None) -> List[tuple]: