Skip to content

Commit

Permalink
Do not cache tags for archived and disabled releases
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Verga <mattia.verga@tiscali.it>
  • Loading branch information
mattiaverga committed Apr 23, 2023
1 parent 29ce3fc commit 7271664
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 32 deletions.
3 changes: 2 additions & 1 deletion bodhi-server/bodhi/server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,8 @@ def get_tags(cls):
data = {'candidate': [], 'testing': [], 'stable': [], 'override': [],
'pending_testing': [], 'pending_stable': []}
tags = {} # tag -> release lookup
for release in cls.query.all():
for release in cls.query.filter(cls.state.notin_([ReleaseState.archived,
ReleaseState.disabled])).all():
for key in data:
tag = getattr(release, f'{key}_tag')
data[key].append(tag)
Expand Down
33 changes: 2 additions & 31 deletions bodhi-server/tests/services/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
Compose,
Group,
ModulePackage,
PackageManager,
Release,
ReleaseState,
RpmBuild,
Expand Down Expand Up @@ -3693,21 +3692,7 @@ def test_edit_update_with_different_release(self, *args):
r = self.app.post_json('/updates/', args)

# Add another release and package
Release.get_tags.cache_clear()
release = Release(
name='F18', long_name='Fedora 18',
id_prefix='FEDORA', version='18',
dist_tag='f18', stable_tag='f18-updates',
testing_tag='f18-updates-testing',
candidate_tag='f18-updates-candidate',
pending_signing_tag='f18-updates-testing-signing',
pending_testing_tag='f18-updates-testing-pending',
pending_stable_tag='f18-updates-pending',
override_tag='f18-override',
branch='f18',
package_manager=PackageManager.unspecified,
testing_repository=None)
self.db.add(release)
self.create_release('18')
pkg = RpmPackage(name='nethack')
self.db.add(pkg)
self.db.commit()
Expand Down Expand Up @@ -4642,21 +4627,7 @@ def test_list_updates_by_alias_and_updateid(self):
def test_submitting_multi_release_updates(self, *args):
""" https://github.com/fedora-infra/bodhi/issues/219 """
# Add another release and package
Release.get_tags.cache_clear()
release = Release(
name='F18', long_name='Fedora 18',
id_prefix='FEDORA', version='18',
dist_tag='f18', stable_tag='f18-updates',
testing_tag='f18-updates-testing',
candidate_tag='f18-updates-candidate',
pending_signing_tag='f18-updates-testing-signing',
pending_testing_tag='f18-updates-testing-pending',
pending_stable_tag='f18-updates-pending',
override_tag='f18-override',
branch='f18',
package_manager=PackageManager.unspecified,
testing_repository=None)
self.db.add(release)
self.create_release('18')
pkg = RpmPackage(name='nethack')
self.db.add(pkg)
self.db.commit()
Expand Down
1 change: 1 addition & 0 deletions news/PR5238.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use functools lru_cache for caching `Release.all_releases()` and `Release.get_tags()` instead of a custom implementation

0 comments on commit 7271664

Please sign in to comment.