Skip to content

Commit

Permalink
Cache results of getting python panel list
Browse files Browse the repository at this point in the history
  • Loading branch information
dsblank committed May 23, 2024
1 parent 4cef8e7 commit db175f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
30 changes: 18 additions & 12 deletions cometx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
"""
Expand Down
2 changes: 2 additions & 0 deletions cometx/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# ****************************************

from IPython.core.magic import register_cell_magic, register_line_magic
from IPython.display import display


def remove_quotes(text):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit db175f6

Please sign in to comment.