avoid precaching users if not worthwhile

If the user specifies individual projects and doesn't need to map email
addresses back to users, caching user <-> BZ email addresses is too much
of an overhead.

fixes: #22

Signed-off-by: Nils Philippsen <nils@redhat.com>
This commit is contained in:
Nils Philippsen 2019-11-22 13:55:49 +01:00
parent 96eb19bcb7
commit 82374d6739

View file

@ -112,7 +112,8 @@ def segment(iterable, chunk, fill=None):
class BugzillaProxy:
def __init__(self, bz_server, username, password, config):
def __init__(self, bz_server, username, password, config,
pre_cache_users=True):
self.bz_xmlrpc_server = bz_server
self.username = username
self.password = password
@ -123,6 +124,7 @@ class BugzillaProxy:
password=self.password)
self.product_cache = {}
self.user_cache = {}
self.inverted_user_cache = {}
# Connect to the fedora account system
@ -133,6 +135,12 @@ class BugzillaProxy:
self.config = config
if not pre_cache_users:
return
if config['verbose']:
print("Pre-caching FAS users and their Bugzilla email addresses.")
try:
self.user_cache = self.fas.people_by_key(
key='username',
@ -140,7 +148,7 @@ class BugzillaProxy:
except fedora.client.ServerError:
# Sometimes, building the user cache up front fails with a timeout.
# It's ok, we build the cache as-needed later in the script.
self.user_cache = {}
pass
else:
self.invert_user_cache()
@ -743,13 +751,15 @@ class DistgitBugzillaSync:
times["data structure end"] = time.time()
delta = times["data structure end"] - times["start"]
print("Ran for %s seconds -- ie: %.2f minutes" % (delta, delta/60.0))
print("Building FAS' cache")
# Initialize the connection to bugzilla
bugzilla = BugzillaProxy(self.env['bugzilla']['url'],
self.env['bugzilla']['user'],
self.env['bugzilla']['password'],
self.env)
bugzilla = BugzillaProxy(
bz_server=self.env['bugzilla']['url'],
username=self.env['bugzilla']['user'],
password=self.env['bugzilla']['password'],
config=self.env,
pre_cache_users=not self.args.projects or self.args.print_fas_names,
)
if self.env["verbose"]:
times["FAS cache building end"] = time.time()