db: check for existing snapshot when with_visit is True in origin_search()
and not only for an existing origin visit.
This is needed in situations where the snapshot table is not in sync with the origin_visit one; typically occurs on mirrors.
Also add tests for with_visit argument.
Migrated from D2295 (view on Phabricator)