[PATCH 1/2] db.py: extract commonly used fetch_userid function