I think @Jens A. is halfway - this is an ideal case for caching, calculating statistics, pasting them into a cache with a fixed expiration time, and then only calculating if they are not in the cache. Having an expiration time corresponding to the corresponding value (5 minutes, less?), The statistics will continue to be quite relevant and will change (update) intelligently without having to calculate each time the pages are constantly updated.
source share