Hi folks,
[Fair disclaimer: I'm not a fan of this scope existing in the first place. We do need better solutions for sharing data across students for the same piece of content. But that's a deeper rabbit hole.]
It is still the case that there is no locking around user_state_summary.
I would strongly caution against making a locking mechanism for it. It is really easy to get tripped up when things start getting busy. Rendering the courseware index can be very slow, meaning that you might be holding that lock for a second or more for a single transaction. You could get into deadlock situations where there are two problems with separate locks, and two users each have one of those locks and is waiting on the other before they can complete their transaction (and causing a pile on for everyone else). You'll also run into bugs caused by the transaction isolation mode the database is set in.
Locking the row can also bite you in really unexpected ways. One of the reasons select_for_update is no longer used for FieldDataCache is that we once had an issue where running a grading task would lock the associated users, preventing an entire course from logging in while it was being graded (logging in updates a user's last_login).
At the end of the day, it can be done. But I believe doing it in a sane way is a lot trickier than it appears to be at first glance.
Do you mind detailing the specific use case?
Take care.
Dave