Query syncing, take two.

This unifies the codepaths for push and pull nicely, instead of having
two strange distinct codepaths.