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

Remove webgateway cache #549

Merged
merged 5 commits 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
1 change: 0 additions & 1 deletion omeroweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,6 @@ def check_session_engine(s):
int,
"Size, in bytes, of the “chunk”",
],
"omero.web.webgateway_cache": ["WEBGATEWAY_CACHE", None, leave_none_unset, None],
"omero.web.maximum_multifile_download_size": [
"MAXIMUM_MULTIFILE_DOWNLOAD_ZIP_SIZE",
1024**3,
Expand Down
118 changes: 30 additions & 88 deletions omeroweb/webgateway/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@

# from models import StoredConnection

from omeroweb.webgateway.webgateway_cache import (
webgateway_cache,
CacheBase,
webgateway_tempfile,
)
from omeroweb.webgateway.webgateway_tempfile import webgateway_tempfile

import logging
import os
Expand All @@ -94,7 +90,6 @@
import numpy


cache = CacheBase()
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -376,8 +371,6 @@ def _render_thumbnail(request, iid, w=None, h=None, conn=None, _defcb=None, **kw
@param h: Thumbnail max height
@return: http response containing jpeg
"""
server_id = request.session["connector"]["server_id"]

server_settings = request.session.get("server_settings", {}).get("browser", {})
defaultSize = server_settings.get("thumb_default_size", 96)

Expand All @@ -391,39 +384,24 @@ def _render_thumbnail(request, iid, w=None, h=None, conn=None, _defcb=None, **kw
size = (int(w), int(h))
if size == (defaultSize,):
direct = False
user_id = conn.getUserId()
z = getIntOrDefault(request, "z", None)
t = getIntOrDefault(request, "t", None)
rdefId = getIntOrDefault(request, "rdefId", None)
# TODO - cache handles rdefId
jpeg_data = webgateway_cache.getThumb(request, server_id, user_id, iid, size)
if jpeg_data is None:
prevent_cache = False
img = conn.getObject("Image", iid)
if img is None:
logger.debug("(b)Image %s not found..." % (str(iid)))
img = conn.getObject("Image", iid)
if img is None:
logger.debug("(b)Image %s not found..." % (str(iid)))
if _defcb:
jpeg_data = _defcb(size=size)
else:
raise Http404("Failed to render thumbnail")
else:
jpeg_data = img.getThumbnail(size=size, direct=direct, rdefId=rdefId, z=z, t=t)
if jpeg_data is None:
logger.debug("(c)Image %s not found..." % (str(iid)))
if _defcb:
jpeg_data = _defcb(size=size)
prevent_cache = True
else:
raise Http404("Failed to render thumbnail")
else:
jpeg_data = img.getThumbnail(
size=size, direct=direct, rdefId=rdefId, z=z, t=t
)
if jpeg_data is None:
logger.debug("(c)Image %s not found..." % (str(iid)))
if _defcb:
jpeg_data = _defcb(size=size)
prevent_cache = True
else:
raise Http404("Failed to render thumbnail")
else:
prevent_cache = img._thumbInProgress
if not prevent_cache:
webgateway_cache.setThumb(request, server_id, user_id, iid, jpeg_data, size)
else:
pass
return jpeg_data


Expand Down Expand Up @@ -1070,15 +1048,11 @@ def render_image_region(request, iid, z, t, conn=None, **kwargs):
else:
return HttpResponseBadRequest("tile or region argument required")

# region details in request are used as key for caching.
jpeg_data = webgateway_cache.getImage(request, server_id, img, z, t)
jpeg_data = img.renderJpegRegion(
z, t, x, y, w, h, level=level, compression=compress_quality
)
if jpeg_data is None:
jpeg_data = img.renderJpegRegion(
z, t, x, y, w, h, level=level, compression=compress_quality
)
if jpeg_data is None:
raise Http404
webgateway_cache.setImage(request, server_id, img, z, t, jpeg_data)
raise Http404

rsp = HttpResponse(jpeg_data, content_type="image/jpeg")
return rsp
Expand Down Expand Up @@ -1106,12 +1080,9 @@ def render_image(request, iid, z=None, t=None, conn=None, **kwargs):
if pi is None:
raise Http404
img, compress_quality = pi
jpeg_data = webgateway_cache.getImage(request, server_id, img, z, t)
jpeg_data = img.renderJpeg(z, t, compression=compress_quality)
if jpeg_data is None:
jpeg_data = img.renderJpeg(z, t, compression=compress_quality)
if jpeg_data is None:
raise Http404
webgateway_cache.setImage(request, server_id, img, z, t, jpeg_data)
raise Http404

format = request.GET.get("format", "jpeg")
rsp = HttpResponse(jpeg_data, content_type="image/jpeg")
Expand Down Expand Up @@ -1177,7 +1148,6 @@ def render_ome_tiff(request, ctx, cid, conn=None, **kwargs):
if dryrun is True, returns count of images that would
be exported
"""
server_id = request.session["connector"]["server_id"]
imgs = []
if ctx == "p":
obj = conn.getObject("Project", cid)
Expand Down Expand Up @@ -1246,17 +1216,14 @@ def render_ome_tiff(request, ctx, cid, conn=None, **kwargs):
return HttpResponseRedirect(
settings.STATIC_URL + "webgateway/tfiles/" + rpath
)
tiff_data = webgateway_cache.getOmeTiffImage(request, server_id, imgs[0])
try:
tiff_data = imgs[0].exportOmeTiff()
except Exception:
logger.debug("Failed to export image (2)", exc_info=True)
tiff_data = None
if tiff_data is None:
try:
tiff_data = imgs[0].exportOmeTiff()
except Exception:
logger.debug("Failed to export image (2)", exc_info=True)
tiff_data = None
if tiff_data is None:
webgateway_tempfile.abort(fpath)
raise Http404
webgateway_cache.setOmeTiffImage(request, server_id, imgs[0], tiff_data)
webgateway_tempfile.abort(fpath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure that this line does anything now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - I missed the unchanged fpath, rpath, fobj = webgateway_tempfile.new(...) above, which makes more sense and explains .abort()

raise Http404
if fobj is None:
rsp = HttpResponse(tiff_data, content_type="image/tiff")
rsp["Content-Disposition"] = 'attachment; filename="%s.ome.tiff"' % (
Expand Down Expand Up @@ -1289,12 +1256,9 @@ def render_ome_tiff(request, ctx, cid, conn=None, **kwargs):
fobj = BytesIO()
zobj = zipfile.ZipFile(fobj, "w", zipfile.ZIP_STORED)
for obj in imgs:
tiff_data = webgateway_cache.getOmeTiffImage(request, server_id, obj)
tiff_data = obj.exportOmeTiff()
if tiff_data is None:
tiff_data = obj.exportOmeTiff()
if tiff_data is None:
continue
webgateway_cache.setOmeTiffImage(request, server_id, obj, tiff_data)
continue
# While ZIP itself doesn't have the 255 char limit for
# filenames, the FS where these get unarchived might, so trim
# names
Expand Down Expand Up @@ -1426,12 +1390,9 @@ def render_split_channel(request, iid, z, t, conn=None, **kwargs):
raise Http404
img, compress_quality = pi
compress_quality = compress_quality and float(compress_quality) or 0.9
jpeg_data = webgateway_cache.getSplitChannelImage(request, server_id, img, z, t)
jpeg_data = img.renderSplitChannel(z, t, compression=compress_quality)
if jpeg_data is None:
jpeg_data = img.renderSplitChannel(z, t, compression=compress_quality)
if jpeg_data is None:
raise Http404
webgateway_cache.setSplitChannelImage(request, server_id, img, z, t, jpeg_data)
raise Http404
rsp = HttpResponse(jpeg_data, content_type="image/jpeg")
return rsp

Expand Down Expand Up @@ -1656,7 +1617,6 @@ def plateGrid_json(request, pid, field=0, conn=None, **kwargs):
prefix = kwargs.get("thumbprefix", "webgateway_render_thumbnail")
thumbsize = getIntOrDefault(request, "size", None)
logger.debug(thumbsize)
server_id = kwargs["server_id"]

def get_thumb_url(iid):
if thumbsize is not None:
Expand All @@ -1679,14 +1639,7 @@ def get_thumb_url(iid):
if plate is None:
return Http404

cache_key = "plategrid-%d-%s" % (field, thumbsize)
rv = webgateway_cache.getJson(request, server_id, plate, cache_key)

if rv is None:
rv = plateGrid.metadata
webgateway_cache.setJson(request, server_id, plate, json.dumps(rv), cache_key)
else:
rv = json.loads(rv)
rv = plateGrid.metadata
return rv


Expand Down Expand Up @@ -2084,8 +2037,6 @@ def save_image_rdef_json(request, iid, conn=None, **kwargs):
if pi is None:
json_data = "false"
else:
user_id = pi[0]._conn.getEventContext().userId
webgateway_cache.invalidateObject(server_id, user_id, pi[0])
pi[0].getThumbnail()
json_data = "true"
if request.GET.get("callback", None):
Expand Down Expand Up @@ -2291,7 +2242,6 @@ def copy_image_rdef_json(request, conn=None, **kwargs):
@return: json dict of Boolean:[Image-IDs]
"""

server_id = request.session["connector"]["server_id"]
json_data = False

fromid = request.GET.get("fromid", None)
Expand Down Expand Up @@ -2370,15 +2320,7 @@ def copy_image_rdef_json(request, conn=None, **kwargs):
except ValueError:
fromid = None
if fromid is not None and len(toids) > 0:
fromimg = conn.getObject("Image", fromid)
userid = fromimg.getOwner().getId()
json_data = conn.applySettingsToSet(fromid, to_type, toids)
if json_data and True in json_data:
for iid in json_data[True]:
img = conn.getObject("Image", iid)
img is not None and webgateway_cache.invalidateObject(
server_id, userid, img
)

# finally - if we temporarily saved rdef to original image, revert
# if we're sure that from-image is not in the target set (Dataset etc)
Expand Down
Loading
Loading