提交 fbdd7d37 编写于 作者: J Jacob Champion

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.
上级 a1dd4ea7
......@@ -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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册