Skip to content

Commit

Permalink
Merge pull request #405 from will-moore/fileset_lazy_loading
Browse files Browse the repository at this point in the history
FilesetWrapper lazy loads Images and UsedFiles
  • Loading branch information
jburel authored Apr 24, 2024
2 parents 65bdd13 + 5ad53eb commit eea0b87
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/omero/gateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7546,32 +7546,41 @@ class _FilesetWrapper (BlitzObjectWrapper):

OMERO_CLASS = 'Fileset'

@classmethod
def _getQueryString(cls, opts=None):
"""
Used for building queries in generic methods such as
getObjects("Fileset").
Returns a tuple of (query, clauses, params).
:param opts: Dictionary of optional parameters.
NB: No options supported for this class.
:return: Tuple of string, list, ParametersI
"""
query = "select obj from Fileset obj "\
"left outer join fetch obj.images as image "\
"left outer join fetch obj.usedFiles as usedFile " \
"join fetch usedFile.originalFile"
return query, [], omero.sys.ParametersI()
def _loadImages(self):
""" Load the Images linked to this Fileset """
params = omero.sys.ParametersI()
params.addId(self.getId())
query_svc = self._conn.getQueryService()
query = "select image from Image as image where image.fileset.id=:id"
self._obj._imagesSeq = query_svc.findAllByQuery(query, params,
self._conn.SERVICE_OPTS)
self._obj._imagesLoaded = True

def copyImages(self):
""" Returns a list of :class:`ImageWrapper` linked to this Fileset """
if not self._obj._imagesLoaded:
self._loadImages()

return [ImageWrapper(self._conn, i) for i in self._obj.copyImages()]

def _loadUsedFiles(self):
""" Load the UsedFiles linked to this Fileset """
params = omero.sys.ParametersI()
params.addId(self.getId())
query_svc = self._conn.getQueryService()
query = "select fse from FilesetEntry as fse join fetch fse.originalFile where fse.fileset.id=:id"
self._obj._usedFilesSeq = query_svc.findAllByQuery(query, params,
self._conn.SERVICE_OPTS)
self._obj._usedFilesLoaded = True

def listFiles(self):
"""
Returns a list of :class:`OriginalFileWrapper` linked to this Fileset
via Fileset Entries
"""
if not self._obj._usedFilesLoaded:
self._loadUsedFiles()

return [OriginalFileWrapper(self._conn, f.originalFile)
for f in self._obj.copyUsedFiles()]

Expand Down

0 comments on commit eea0b87

Please sign in to comment.