thewca / worldcubeassociation.org

All of the code that runs on worldcubeassociation.org
https://www.worldcubeassociation.org/
GNU General Public License v3.0
318 stars 172 forks source link

Incomplete ranks shown while CAD is running #9569

Open jonatanklosko opened 1 week ago

jonatanklosko commented 1 week ago

We have the manually-triggered background job for computing ranks information (CAD). For each of the ranks tables, it removes all rows, then computes and inserts fresh rows. While the computation is running, the ranks tables have missing information, which surfaces in the UI and API.

Here are a few screenshots while running CAD on the staging, where it can be seen how CAD progresses:

Screenshots * Records showing only average as ConciseSingleResults are being computed image * Records showing only single as ConciseAverageResults are being computed image * Incremental entries in the profile as RanksSingle are being computed image image

The same issue affects API endpoints that rely on ranks (records, WCIF personal bests), and that is a bigger problem, because API users definitely don't expect records to suddenly have no entries.

For more context, I believe this is the underlying issue behind a few strange false-positive record tags we've seen on WCA Live https://github.com/thewca/wca-live/issues/145.

Note that some of the pages/endpoints are cached, so keep that in mind when reproducing.

gregorbg commented 1 week ago

Interesting... Taking a complete shot in the dark here but would wrapping the whole CAD process into a transaction help?

jonatanklosko commented 1 week ago

We already update each table in a transaction, so it should be atomic:

https://github.com/thewca/worldcubeassociation.org/blob/1e83c26f9b204bfbd236c6a074fff309eb9d8a47/lib/auxiliary_data_computation.rb#L15-L19

Just looking at the code I don't have any reasonable idea, unless the queries skip the transaction somehow. One option to test would be to add rollback after the delete and see if that works as expected.