Skip to content

Commit 9def7db

Browse files
zetter-rpfCopilot
andauthored
Prevent stale submitted project count
Add lock to prevent stale reads in the case this runs concurrently for the same project Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 07cc1ce commit 9def7db

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

app/models/lesson.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ def submitted_count
4141
end
4242

4343
def recalculate_submitted_projects_count!
44-
count = school_projects.in_state(:submitted).count
45-
update!(submitted_projects_count: count)
44+
with_lock do
45+
count = school_projects.in_state(:submitted).count
46+
update!(submitted_projects_count: count)
47+
end
4648
end
4749

4850
private

0 commit comments

Comments
 (0)