Move this query and check to right before line 645 so we don't hit the database unless the request itself contains valid data.