optimise view count calculation query