Skip to content

Commit 72dfe97

Browse files
author
Nils Bars
committed
Eager-load and expunge Exercise.config in the build thread
The build thread detaches the Exercise plus its forward relationships so attribute access during the long-running Docker build does not trigger a lazy load that would reopen a transaction and hold the build advisory lock. Extends that pattern to the config relationship added with ExerciseConfig, otherwise touching exercise.config in __run_build raises DetachedInstanceError.
1 parent 2b18323 commit 72dfe97

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

webapp/ref/core/image.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ def __run_build_by_id(app, exercise_id: int):
448448
exercise = Exercise.query.options(
449449
joinedload(Exercise.entry_service),
450450
joinedload(Exercise.services),
451+
joinedload(Exercise.config),
451452
).get(exercise_id)
452453
if exercise is None:
453454
_log_build(
@@ -470,13 +471,15 @@ def __run_build_by_id(app, exercise_id: int):
470471
# only populates forward relationships, not reverse ones.
471472
entry_service = exercise.entry_service
472473
services = list(exercise.services)
474+
config = exercise.config
473475
app.db.session.expunge(exercise)
474476
if entry_service:
475477
app.db.session.expunge(entry_service)
476478
entry_service.exercise = exercise
477479
for svc in services:
478480
app.db.session.expunge(svc)
479481
svc.exercise = exercise
482+
app.db.session.expunge(config)
480483
app.db.session.commit()
481484
ExerciseImageManager.__run_build(app, exercise)
482485
_log_build(f"[BUILD] Build thread finished for exercise_id={exercise_id}")

0 commit comments

Comments
 (0)