Skip to content

Commit 4f78e8f

Browse files
authored
[card-client] make Card.get_data more efficient (#1750)
* [card-client] make `Card.get_data` more efficient * [card-updates] hold a time.time value in data updates - Helps ensure that stale updates from a server can be ignored * [card-ui] remove unecessary console logs
1 parent cb7e945 commit 4f78e8f

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

metaflow/plugins/cards/card_cli.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111
from metaflow._vendor import click
1212
import os
13+
import time
1314
import json
1415
import uuid
1516
import signal
@@ -454,7 +455,11 @@ def _add_token_html(html):
454455
def _add_token_json(json_msg):
455456
if json_msg is None:
456457
return None
457-
return {"reload_token": _reload_token(), "data": json_msg}
458+
return {
459+
"reload_token": _reload_token(),
460+
"data": json_msg,
461+
"created_on": time.time(),
462+
}
458463

459464
def _safe_call_function(func, *args, **kwargs):
460465
"""

metaflow/plugins/cards/card_client.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(
4747
self._created_on = created_on
4848
self._card_ds = card_ds
4949
self._card_id = id
50+
self._data_path = None
5051

5152
# public attributes
5253
self.hash = hash
@@ -59,12 +60,14 @@ def __init__(
5960

6061
def get_data(self) -> Optional[dict]:
6162
# currently an internal method to retrieve a card's data.
62-
data_paths = self._card_ds.extract_data_paths(
63-
card_type=self.type, card_hash=self.hash, card_id=self._card_id
64-
)
65-
if len(data_paths) == 0:
66-
return None
67-
return self._card_ds.get_card_data(data_paths[0])
63+
if self._data_path is None:
64+
data_paths = self._card_ds.extract_data_paths(
65+
card_type=self.type, card_hash=self.hash, card_id=self._card_id
66+
)
67+
if len(data_paths) == 0:
68+
return None
69+
self._data_path = data_paths[0]
70+
return self._card_ds.get_card_data(self._data_path)
6871

6972
def get(self) -> str:
7073
"""

metaflow/plugins/cards/card_modules/main.js

+17-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

metaflow/plugins/cards/ui/src/store.ts

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ export const cardData: Writable<types.CardResponse | undefined> =
1414
(window as any).metaflow_card_update = (
1515
dataChanges: Record<string, types.CardComponent>
1616
) => {
17-
console.log("metaflow_card_update", dataChanges, cardData?.update);
18-
1917
cardData?.update((d: any) => {
2018
const newData: types.CardResponse = { ...d };
2119

0 commit comments

Comments
 (0)