From dd82b8252e4fa3a0cc50a518b29d822038ae65a4 Mon Sep 17 00:00:00 2001 From: Alan Christie Date: Thu, 30 May 2024 12:42:48 +0100 Subject: [PATCH 1/2] refactor: Adds extra logging in proposal extraction --- api/security.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/api/security.py b/api/security.py index 4b03a091..31411380 100644 --- a/api/security.py +++ b/api/security.py @@ -52,6 +52,8 @@ def has_expired(username) -> bool: has_expired = True # Expired, reset the expiry time CachedContent._timers[username] = now + CachedContent._cache_period + if has_expired: + logger.info("Content expired for '%s'", username) return has_expired @staticmethod @@ -59,12 +61,15 @@ def get_content(username): with CachedContent._cache_lock: if username not in CachedContent._content: CachedContent._content[username] = [] - return CachedContent._content[username] + content = CachedContent._content[username] + logger.info("Got content for '%s': %s", username, content) + return content @staticmethod def set_content(username, content) -> None: with CachedContent._cache_lock: CachedContent._content[username] = content.copy() + logger.info("Set content for '%s': %s", username, content) def get_remote_conn(force_error_display=False) -> Optional[SSHConnector]: @@ -244,7 +249,7 @@ def _get_proposals_for_user_from_ispyb(self, user): logger.info("Cache has expired for '%s'", user.username) PrometheusMetrics.new_proposal_cache_miss() if conn := get_configured_connector(): - logger.debug("Got a connector for '%s'", user.username) + logger.info("Got a connector for '%s'", user.username) self._get_proposals_from_connector(user, conn) else: logger.warning("Failed to get a connector for '%s'", user.username) @@ -315,9 +320,9 @@ def _get_proposals_from_connector(self, user, conn): proposal_visit_str = f'{proposal_str}-{sn_str}' prop_id_set.update([proposal_str, proposal_visit_str]) - # Always display the collected results for the user. + # Display the collected results for the user. # These will be cached. - logger.debug( + logger.info( "%s proposals from %s records for '%s': %s", len(prop_id_set), len(rs), From e8c24a518b5de7bcfb0e1fde3614cc6cfeabe12d Mon Sep 17 00:00:00 2001 From: Alan Christie Date: Thu, 30 May 2024 12:50:02 +0100 Subject: [PATCH 2/2] style: Initial cache now a set rather than empty list --- api/security.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/security.py b/api/security.py index 31411380..e17ac726 100644 --- a/api/security.py +++ b/api/security.py @@ -60,7 +60,7 @@ def has_expired(username) -> bool: def get_content(username): with CachedContent._cache_lock: if username not in CachedContent._content: - CachedContent._content[username] = [] + CachedContent._content[username] = set() content = CachedContent._content[username] logger.info("Got content for '%s': %s", username, content) return content