DbURL: improve constructor performance
When constructing a DbURL without an explicit username, /usr/bin/id was
executed regardless of whether we needed its output or not. That seems
excessive; let's only use it if the environment doesn't already have
what we need.
@@ -114,7 +114,10 @@ class DbURL:
self.pgdb = dbname
if username is None:
- self.pguser = os.environ.get('PGUSER', os.environ.get('USER', UserId.local('Get uid')))
+ self.pguser = os.environ.get('PGUSER', os.environ.get('USER', None))
+ if self.pguser is None:
+ # fall back to /usr/bin/id
+ self.pguser = UserId.local('Get uid')
if self.pguser is None or self.pguser == '':
raise Exception('Both $PGUSER and $USER env variables are not set!')
else:
