metadata: do not unnecessarily query the database if there’s no chance that it will yield a result