handlers/front: fix sqlalchemy query

Querying on an empty sequence is expensive.