Don't make so many queries for user info when building UserOption form

This commit is contained in:
selfhoster1312 2023-11-04 14:36:32 +01:00
parent f56f235705
commit 8ee5aade72

View file

@ -941,9 +941,11 @@ class UserOption(BaseChoicesOption):
super().__init__(question) super().__init__(question)
users = user_list(fields = ["username", "fullname", "mail", "mail-alias"])["users"]
self.choices = { self.choices = {
username: f"{infos['fullname']} ({infos['mail']})" username: f"{infos['fullname']} ({infos['mail']})"
for username, infos in user_list()["users"].items() for username, infos in users.items()
} }
if not self.choices: if not self.choices:
@ -958,7 +960,7 @@ class UserOption(BaseChoicesOption):
# Should be replaced by something like "any first user we find in the admin group" # Should be replaced by something like "any first user we find in the admin group"
root_mail = "root@%s" % _get_maindomain() root_mail = "root@%s" % _get_maindomain()
for user in self.choices.keys(): for user in self.choices.keys():
if root_mail in user_info(user).get("mail-aliases", []): if root_mail in users[user].get("mail-aliases", []):
self.default = user self.default = user
break break