Instead of doing the historical analysis on each request on the web frontend, do it directly after re-ingesting and either store it in memcached, or directly in postgres in a json field. This could also be done on the web side if deemed too complicated.