Optimize sql speed of realtime page