Whilst logged into Sales as a staff member, you can see the number of items available for each performance:
The version-before-last had a bug whereby this information was not displayed
because of some unfinished work that slipped into the build. This is now working properly, but it doesn’t display the quantities every time, and I thought I’d explain why not, and why we made the change.
Counting these quantities can be an expensive operation in terms of server resources. It’s not expensive when you’re looking at just one performance, but when you’re looking at a home page full of different shows, each of which has a run over many dates, there’s lots of data for the server to crunch.
Obviously, we cache this data so we don’t have to look it up every page refresh. But we had a problem with the way this data was being cached, with large on-sales in particular.
When there were lots of people on the site all at once, and the cached data was invalidated, lots of session would request the page at the same instant. Let’s say that normally it takes 1 second to load this data from the database, and 0 seconds once the data is in the cache. If we have a busy on sale - let’s say 10 page refreshes in the same second - everyone who tries to get the page in that second looks in the cache, finds the data isn’t there, and starts a query to return it. And the system waits for that data to be selected. Which means we have 10 queries all doing the same thing at once. And that query which would normally take 1 second now takes 2, because there are 10 queries all running at the same time. Which means that the results aren’t written back to the cache for another second, which mean that in the next second, 10 more people request the page, and THEY find the data not in the cache too, and so they query the database… and we get a pile up.
What we have done is change it so the first time this data is requested, instead of fetching it, putting it in the cache, and returning it, instead we
- Return a blank object with no data.
- Put the blank object in the cache
- Start a process to run the query and cache the result when it’s finished.
This means that the first page request (and any that happen in that second until the cache is populated) doesn’t get the quantity data, but everyone subsequently does, and it doesn’t result in any performance problems.
So: if you look at a page and the quantities aren’t displayed, refresh it, and they will be!