optimize queries
optimization to logs query