Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve upstream download speed #275

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/murfey/client/tui/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,12 @@ def on_button_pressed(self, event: Button.Pressed):
upstream_tiff_paths = upstream_tiff_paths_response.json()
for tp in upstream_tiff_paths:
(download_dir / tp).parent.mkdir(exist_ok=True, parents=True)
stream_response = requests.get(
f"{self.app._environment.url.geturl()}/visits/{event.button.label}/upstream_tiff/{tp}",
stream=True,
)
with open(download_dir / tp, "wb") as utiff:
stream_response = requests.get(
f"{self.app._environment.url.geturl()}/visits/{event.button.label}/upstream_tiff/{tp}",
stream=True,
)
for chunk in stream_response.iter_content():
for chunk in stream_response.iter_content(chunk_size=32 * 1024**2):
utiff.write(chunk)
self.app.pop_screen()

Expand Down
12 changes: 2 additions & 10 deletions src/murfey/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import packaging.version
import sqlalchemy
from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse, StreamingResponse
from fastapi.responses import FileResponse, HTMLResponse
from ispyb.sqlalchemy import AutoProcProgram as ISPyBAutoProcProgram
from ispyb.sqlalchemy import (
BLSample,
Expand Down Expand Up @@ -1640,12 +1640,4 @@ async def get_tiff(visit_name: str, tiff_path: str):

tiff_path = "/".join(secure_filename(p) for p in tiff_path.split("/"))

def iterfile():
with open(processed_dir / tiff_path, mode="rb") as f:
yield from f

return StreamingResponse(
iterfile(),
media_type="image/tiff",
headers={"Content-Disposition": f"attachment; filename={Path(tiff_path).name}"},
)
return FileResponse(path=processed_dir / tiff_path)
12 changes: 2 additions & 10 deletions src/murfey/server/demo_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import packaging.version
import sqlalchemy
from fastapi import APIRouter, Request
from fastapi.responses import FileResponse, HTMLResponse, StreamingResponse
from fastapi.responses import FileResponse, HTMLResponse
from ispyb.sqlalchemy import BLSession
from PIL import Image
from pydantic import BaseModel, BaseSettings
Expand Down Expand Up @@ -1475,12 +1475,4 @@ async def get_tiff(visit_name: str, tiff_path: str):

tiff_path = "/".join(secure_filename(p) for p in tiff_path.split("/"))

def iterfile():
with open(processed_dir / tiff_path, mode="rb") as f:
yield from f

return StreamingResponse(
iterfile(),
media_type="image/tiff",
headers={"Content-Disposition": f"attachment; filename={Path(tiff_path).name}"},
)
return FileResponse(path=processed_dir / tiff_path)