optimize main page db queries