mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-05-03 22:44:29 +08:00
Use dogpile.cache to cache the default_buildroot_groups result
This commit is contained in:
@@ -1375,3 +1375,31 @@ def get_rpm_release_from_mmd(mmd):
|
||||
dist_str = '.'.join([mmd.name, mmd.stream, str(mmd.version)])
|
||||
dist_hash = hashlib.sha1(dist_str).hexdigest()[:8]
|
||||
return conf.default_dist_tag_prefix + dist_hash
|
||||
|
||||
def create_dogpile_key_generator_func(skip_first_n_args=0):
|
||||
"""
|
||||
Creates dogpile key_generator function with additional features:
|
||||
|
||||
- when models.ModuleBuild is an argument of method cached by dogpile-cache,
|
||||
the ModuleBuild.id is used as a key. Therefore it is possible to cache
|
||||
data per particular module build, while normally, it would be per
|
||||
ModuleBuild.__str__() output, which contains also batch and other data
|
||||
which changes during the build of a module.
|
||||
- it is able to skip first N arguments of a cached method. This is useful
|
||||
when the db.session or PDCClient instance is part of cached method call,
|
||||
and the caching should work no matter what session instance is passed
|
||||
to cached method argument.
|
||||
"""
|
||||
def key_generator(namespace, fn):
|
||||
fname = fn.__name__
|
||||
def generate_key(*arg, **kwarg):
|
||||
key_template = fname + "_"
|
||||
for s in arg[skip_first_n_args:]:
|
||||
if type(s) == models.ModuleBuild:
|
||||
key_template += str(s.id)
|
||||
else:
|
||||
key_template += str(s) + "_"
|
||||
return key_template
|
||||
|
||||
return generate_key
|
||||
return key_generator
|
||||
|
||||
Reference in New Issue
Block a user