Skip to content

Commit 909b823

Browse files
author
codeEmpress1
committed
add cache to endponits/publisher/build
1 parent ac12365 commit 909b823

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

webapp/endpoints/builds.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from webapp.helpers import api_publisher_session, launchpad
1111
from webapp.api.github import GitHub
1212
from webapp.decorators import login_required
13+
from cache.cache_utility import redis_cache
1314

1415
GITHUB_SNAPCRAFT_USER_TOKEN = os.getenv("GITHUB_SNAPCRAFT_USER_TOKEN")
1516
GITHUB_WEBHOOK_HOST_URL = os.getenv("GITHUB_WEBHOOK_HOST_URL")
@@ -22,7 +23,11 @@ def get_snap_repo(snap_name):
2223
res = {"message": "", "success": True}
2324
data = {"github_orgs": [], "github_repository": None, "github_user": None}
2425

25-
details = dashboard.get_snap_info(flask.session, snap_name)
26+
snap_info_key = f"snap_info:{snap_name}"
27+
details = redis_cache.get(snap_info_key, expected_type=dict)
28+
if not details:
29+
details = dashboard.get_snap_info(flask.session, snap_name)
30+
redis_cache.set(snap_info_key, details, ttl=3600)
2631

2732
# API call to make users without needed permissions refresh the session
2833
# Users needs package_upload_request permission to use this feature

0 commit comments

Comments
 (0)