From db175f6831bd95ff8284c2fd5cbaf8a5b708f56a Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Thu, 23 May 2024 09:10:17 -0400 Subject: [PATCH] Cache results of getting python panel list --- cometx/api.py | 30 ++++++++++++++++++------------ cometx/magics.py | 2 ++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/cometx/api.py b/cometx/api.py index 79b44f3..a9ae052 100644 --- a/cometx/api.py +++ b/cometx/api.py @@ -11,8 +11,12 @@ # Team. All rights reserved. # **************************************** +from collections import defaultdict + from comet_ml import API +CACHE = defaultdict(dict) + class API(API): def get_panels(self, workspace): @@ -42,18 +46,20 @@ def get_panels(self, workspace): return results["codePanelTemplateRows"] def get_python_panels(self, workspace): - templates = self.get_panels(workspace) - results = [] - for template in templates: - template_data = self.get_panel(template["templateId"]) - if ( - "code" in template_data - and "type" in template_data["code"] - and template_data["code"]["type"] == "py" - ): - template["code"] = template_data["code"]["pyCode"] - results.append(template) - return results + if workspace not in CACHE["get_python_panels"]: + templates = self.get_panels(workspace) + results = [] + for template in templates: + template_data = self.get_panel(template["templateId"]) + if ( + "code" in template_data + and "type" in template_data["code"] + and template_data["code"]["type"] == "py" + ): + template["code"] = template_data["code"]["pyCode"] + results.append(template) + CACHE["get_python_panels"][workspace] = results + return CACHE["get_python_panels"][workspace] def get_panel(self, template_id=None, instance_id=None): """ diff --git a/cometx/magics.py b/cometx/magics.py index 54da626..d563612 100644 --- a/cometx/magics.py +++ b/cometx/magics.py @@ -12,6 +12,7 @@ # **************************************** from IPython.core.magic import register_cell_magic, register_line_magic +from IPython.display import display def remove_quotes(text): @@ -50,6 +51,7 @@ def cometx(line, cell=None): if cell is None: if panel_name is None: + display("Loading Python Panels...") cell = """ from cometx import API from comet_ml import ui