Skip to content

Commit

Permalink
consume generator in batches of 16 (#742)
Browse files Browse the repository at this point in the history
* consume generator in batches of 16

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* bugfix, zeroth frame from default room

* remove comment

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
PythonFZ and pre-commit-ci[bot] authored Nov 18, 2024
1 parent e73c179 commit 4ec7abb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/src/components/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ export const setupFrames = (
};

const currentRoomCon = useMemo(() => {
if (token === "") {
return undefined;
}
return new znsocket.List({
client,
key: `room:${token}:frames`,
Expand Down Expand Up @@ -445,7 +448,7 @@ export const setupFrames = (
return () => {
clearTimeout(debounceTimeout);
};
}, [step, updateStepInPlace]);
}, [step, updateStepInPlace, defaultRoomCon, currentRoomCon]);

// Sending edits from ZnDraw to the server
useEffect(() => {
Expand Down
12 changes: 8 additions & 4 deletions zndraw/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def upload(
append: bool,
plots: list[str],
browser: bool,
batch_size: int = 16,
):
"""Upload a file to ZnDraw."""
if token is None:
Expand All @@ -34,12 +35,15 @@ def upload(

generator = get_generator_from_filename(fileio)

frames = list(generator)
vis.append(frames[0])
if browser:
webbrowser.open(f"{url}/token/{vis.token}")

if len(frames) > 1:
vis.extend(frames[1:])
frames = []
for frame in generator:
frames.append(frame)
if len(frames) == batch_size:
vis.extend(frames)
frames = []
vis.extend(frames)

vis.figures.update(load_plots_to_dict(plots, fileio.remote, fileio.rev))

0 comments on commit 4ec7abb

Please sign in to comment.