perf: skip fact extraction for fully graded projects on batch retries

This commit is contained in:
2026-10-17 20:44:24 +08:00
parent 050aa4e02a
commit 14cef5c929
2 changed files with 49 additions and 0 deletions
+12
View File
@@ -358,6 +358,18 @@ def _run_project(batch_id, project_id, session_factory, client_factory, embedder
with session_factory() as db:
batch = db.get(ScoringBatch, batch_id)
project = db.get(Project, project_id)
existing = db.scalars(select(CriterionScore).where(CriterionScore.batch_id == batch_id,
CriterionScore.project_id == project_id)).all()
graded = {score.criterion_id for score in existing
if score.status in (STATUS_SCORED, STATUS_REVIEWED)}
criteria = batch.rubric_snapshot["criteria"]
if all(criterion["criterion_id"] in graded for criterion in criteria):
# A retry in a multi-student batch must not spend two more model calls
# extracting facts for a student whose scores will all be skipped.
db.execute(update(ScoringBatch).where(ScoringBatch.id == batch_id).values(
progress_done=ScoringBatch.progress_done + len(criteria)))
db.commit()
return 0, 0
try:
client = client_factory(db, batch)
except Exception: