z230
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
def log_event(cur, file_id, event_type, old=None, new=None):
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO file_events (
|
||||
file_id, event_type, event_time,
|
||||
old_size, new_size,
|
||||
old_hash, new_hash
|
||||
from indexer.config import BATCH_SIZE
|
||||
|
||||
|
||||
def batch_log_events(cur, events: list):
|
||||
"""
|
||||
Batch INSERT eventů do file_events.
|
||||
events: [{run_id, file_id, event_type, old_size, new_size, old_hash, new_hash}]
|
||||
"""
|
||||
if not events:
|
||||
return
|
||||
for i in range(0, len(events), BATCH_SIZE):
|
||||
chunk = events[i:i + BATCH_SIZE]
|
||||
cur.executemany(
|
||||
"""INSERT INTO file_events
|
||||
(run_id, file_id, event_type, old_size, new_size, old_hash, new_hash)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s)""",
|
||||
[(e["run_id"], e["file_id"], e["event_type"],
|
||||
e.get("old_size"), e.get("new_size"),
|
||||
e.get("old_hash"), e.get("new_hash"))
|
||||
for e in chunk]
|
||||
)
|
||||
VALUES (%s, %s, NOW(), %s, %s, %s, %s)
|
||||
""",
|
||||
(
|
||||
file_id,
|
||||
event_type,
|
||||
old["size"] if old else None,
|
||||
new["size"] if new else None,
|
||||
old["content_hash"] if old else None,
|
||||
new["content_hash"] if new else None,
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user