z230
This commit is contained in:
@@ -79,10 +79,15 @@ def batch_insert_files(cur, files_list: list, run_id: int) -> dict:
|
||||
f["size"], f["mtime"], f["content_hash"], run_id, run_id)
|
||||
for f in chunk]
|
||||
)
|
||||
# pymysql executemany: lastrowid = first id in batch
|
||||
first_id = cur.lastrowid
|
||||
for j, f in enumerate(chunk):
|
||||
path_to_id[f["relative_path"]] = first_id + j
|
||||
# Fetch real IDs — lastrowid+j is unreliable with executemany
|
||||
paths = [f["relative_path"] for f in chunk]
|
||||
placeholders = ",".join(["%s"] * len(paths))
|
||||
cur.execute(
|
||||
f"SELECT id, relative_path FROM files WHERE relative_path IN ({placeholders})",
|
||||
paths,
|
||||
)
|
||||
for row in cur.fetchall():
|
||||
path_to_id[row[1]] = row[0]
|
||||
return path_to_id
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user