optimize heats query