Optimize query for fetching to-device messages in `/sync`.