learning-unlimited/ESP-Website — comment on commit 2295173fe9e1d569667ee24c7440b72a989387de
File: esp/esp/program/models/class_.py line 970
By aseering:

You would think .count() would be cached, but in my experience it is not. (This may have been fixed in recent-Django; it is a little silly, I think, though it's in line with the semantics "you get a new query exactly when you add any new conditions to a QuerySet by calling a new function on it.")

Also, beware that executing it does not execute the query; it executes a simpler query that just returns the count, a single integer. (It's a "SELECT COUNT(*)" query, if you know SQL.)

"ordered": Ooh, shiny; I didn't actually know about that. I assume this logic wants "ordered by start-time", though? The "ordered" field appears to just indicate any sort of ordering; could be by ID, which for a typical program means roughly by time except for that one time block that we forgot to add and added later, causing results that are wrong in subtle and annoying-to-track-down ways.