From a31b011482e27a5f3f86275cf96cee5962de8880 Mon Sep 17 00:00:00 2001 From: Andreas Knab Date: Mon, 31 Jul 2023 17:20:38 +0200 Subject: [PATCH 1/3] Cache script names --- omeroweb/webclient/controller/container.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/omeroweb/webclient/controller/container.py b/omeroweb/webclient/controller/container.py index 2336ed3449..4226622fb3 100644 --- a/omeroweb/webclient/controller/container.py +++ b/omeroweb/webclient/controller/container.py @@ -27,6 +27,7 @@ from omero.rtypes import rstring, rlong, unwrap from django.utils.encoding import smart_str import logging +import time from omeroweb.webclient.controller import BaseController from omeroweb.webgateway.views import _bulk_file_annotations @@ -61,6 +62,9 @@ class BaseContainer(BaseController): orphaned = False + _list_scripts_cache = [] + _list_scripts_cache_timestamp = 0 + def __init__( self, conn, @@ -315,6 +319,11 @@ def list_scripts(self): """ Get the file names of all scripts """ + now = time.time() + if now - BaseContainer._list_scripts_cache_timestamp < 60: + # cache 10 minutes + return BaseContainer._list_scripts_cache + scriptService = self.conn.getScriptService() scripts = scriptService.getScripts() @@ -324,6 +333,9 @@ def list_scripts(self): name = s.name.val scriptlist.append(name) + BaseContainer._list_scripts_cache = scriptlist + BaseContainer._list_scripts_cache_timestamp = now + return scriptlist def listFigureScripts(self, objDict=None): From 52c3c5bfd1abb5e7b2dc049e454f1c02a12ec8cc Mon Sep 17 00:00:00 2001 From: Andreas Knab Date: Tue, 22 Aug 2023 10:16:38 +0200 Subject: [PATCH 2/3] Set timeout to 10 minutes --- omeroweb/webclient/controller/container.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omeroweb/webclient/controller/container.py b/omeroweb/webclient/controller/container.py index 4226622fb3..487c7f6146 100644 --- a/omeroweb/webclient/controller/container.py +++ b/omeroweb/webclient/controller/container.py @@ -320,7 +320,7 @@ def list_scripts(self): Get the file names of all scripts """ now = time.time() - if now - BaseContainer._list_scripts_cache_timestamp < 60: + if now - BaseContainer._list_scripts_cache_timestamp < 600: # cache 10 minutes return BaseContainer._list_scripts_cache From faa0992c501293e6189fc9fac10e2b8c65112917 Mon Sep 17 00:00:00 2001 From: Andreas Knab Date: Fri, 1 Sep 2023 12:08:24 +0200 Subject: [PATCH 3/3] Keep cached scripts in request session --- omeroweb/webclient/controller/container.py | 21 ++++++++------------- omeroweb/webclient/views.py | 4 ++-- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/omeroweb/webclient/controller/container.py b/omeroweb/webclient/controller/container.py index 487c7f6146..7412506a84 100644 --- a/omeroweb/webclient/controller/container.py +++ b/omeroweb/webclient/controller/container.py @@ -27,7 +27,6 @@ from omero.rtypes import rstring, rlong, unwrap from django.utils.encoding import smart_str import logging -import time from omeroweb.webclient.controller import BaseController from omeroweb.webgateway.views import _bulk_file_annotations @@ -62,9 +61,6 @@ class BaseContainer(BaseController): orphaned = False - _list_scripts_cache = [] - _list_scripts_cache_timestamp = 0 - def __init__( self, conn, @@ -315,14 +311,13 @@ def canDownload(self, objDict=None): or self.plate.canDownload() ) - def list_scripts(self): + def list_scripts(self, request=None): """ Get the file names of all scripts """ - now = time.time() - if now - BaseContainer._list_scripts_cache_timestamp < 600: - # cache 10 minutes - return BaseContainer._list_scripts_cache + + if request and "list_scripts" in request.session: + return request.session["list_scripts"] scriptService = self.conn.getScriptService() scripts = scriptService.getScripts() @@ -333,19 +328,19 @@ def list_scripts(self): name = s.name.val scriptlist.append(name) - BaseContainer._list_scripts_cache = scriptlist - BaseContainer._list_scripts_cache_timestamp = now + if request: + request.session["list_scripts"] = scriptlist return scriptlist - def listFigureScripts(self, objDict=None): + def listFigureScripts(self, objDict=None, request=None): """ This configures all the Figure Scripts, setting their enabled status given the currently selected object (self.image etc) or batch objects (uses objDict) and the script availability. """ - availableScripts = self.list_scripts() + availableScripts = self.list_scripts(request=request) image = None if self.image or self.well: image = self.image or self.getWellSampleImage() diff --git a/omeroweb/webclient/views.py b/omeroweb/webclient/views.py index 2435222042..b7d939c62c 100755 --- a/omeroweb/webclient/views.py +++ b/omeroweb/webclient/views.py @@ -1738,7 +1738,7 @@ def load_metadata_details(request, c_type, c_id, conn=None, share_id=None, **kwa context["canExportAsJpg"] = manager.canExportAsJpg(request) context["annotationCounts"] = manager.getAnnotationCounts() context["tableCountsOnParents"] = manager.countTablesOnParents() - figScripts = manager.listFigureScripts() + figScripts = manager.listFigureScripts(request=request) context["manager"] = manager if c_type in ("tag", "tagset"): @@ -2280,7 +2280,7 @@ def batch_annotate(request, conn=None, **kwargs): conn.SERVICE_OPTS.setOmeroGroup(groupId) manager = BaseContainer(conn) - figScripts = manager.listFigureScripts(objs) + figScripts = manager.listFigureScripts(objs, request=request) canExportAsJpg = manager.canExportAsJpg(request, objs) filesetInfo = None iids = []