Fix infinite loop in find_unprocessed: check sha256 content (not just path), record dup paths; Optional[int] for max_batches
This commit is contained in:
@@ -42,20 +42,28 @@ def find_unprocessed(base_dir: str, batch_size: int, source: str = None) -> list
|
||||
conn = db.get_db()
|
||||
batch = []
|
||||
for p_str in walk_files(base_dir):
|
||||
# skip if already registered for this source (or any source)
|
||||
row = conn.execute(
|
||||
"SELECT 1 FROM image_hashes WHERE sha256=?",
|
||||
(db.sha256_file(p_str),),
|
||||
).fetchone() if False else None
|
||||
# cheap check: path already known?
|
||||
known = conn.execute(
|
||||
"SELECT 1 FROM image_hashes WHERE path=?", (p_str,)
|
||||
).fetchone()
|
||||
if known:
|
||||
continue
|
||||
# content check: sha256 already registered (catches same photo at other paths)
|
||||
sha = db.sha256_file(p_str)
|
||||
sha_known = conn.execute(
|
||||
"SELECT 1 FROM image_hashes WHERE sha256=?", (sha,)
|
||||
).fetchone()
|
||||
if sha_known:
|
||||
# record this path too, so we don't re-hash it every loop
|
||||
conn.execute(
|
||||
"INSERT OR IGNORE INTO image_hashes (sha256, phash, dhash, file_size, path, source) "
|
||||
"SELECT sha256, phash, dhash, file_size, ?, source FROM image_hashes WHERE sha256=?",
|
||||
(p_str, sha))
|
||||
continue
|
||||
batch.append(p_str)
|
||||
if len(batch) >= batch_size:
|
||||
break
|
||||
conn.commit()
|
||||
conn.close()
|
||||
print(f"find_unprocessed: {len(batch)} new files (batch_size={batch_size})")
|
||||
return batch
|
||||
@@ -112,7 +120,7 @@ def check_and_register(image_paths: list[str], source: str) -> dict:
|
||||
|
||||
@flow(name="photo-ingest")
|
||||
def photo_ingest(base_dir: str, source: str = "takeout", batch_size: int = 1000,
|
||||
max_batches: int = None):
|
||||
max_batches: int | None = None):
|
||||
"""Hash + dedup-check a folder against the persistent library, in batches.
|
||||
|
||||
Args:
|
||||
|
||||
Reference in New Issue
Block a user