Skip to content

Commit

Permalink
Merge pull request #684 from girder/guard-caching-on-ro-assetstores
Browse files Browse the repository at this point in the history
Guard caching on read-only assetstores.
  • Loading branch information
manthey authored Nov 17, 2021
2 parents 5439255 + 23f5d45 commit 619fcc9
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions girder/girder_large_image/models/image_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from girder import logger
from girder.constants import SortDir
from girder.exceptions import FilePathException, ValidationException
from girder.exceptions import FilePathException, GirderException, ValidationException
from girder.models.assetstore import Assetstore
from girder.models.file import File
from girder.models.item import Item
Expand Down Expand Up @@ -360,21 +360,24 @@ def _getAndCacheImageOrData(
pickleCache or isinstance(imageData, bytes))):
dataStored = imageData if not pickleCache else pickle.dumps(imageData, protocol=4)
# Save the data as a file
datafile = Upload().uploadFromFile(
io.BytesIO(dataStored), size=len(dataStored),
name='_largeImageThumbnail', parentType='item', parent=item,
user=None, mimeType=imageMime, attachParent=True)
if not len(dataStored) and 'received' in datafile:
datafile = Upload().finalizeUpload(
datafile, Assetstore().load(datafile['assetstoreId']))
datafile.update({
'isLargeImageThumbnail' if not pickleCache else 'isLargeImageData': True,
'thumbnailKey': key,
})
# Ideally, we would check that the file is still wanted before we
# save it. This is probably impossible without true transactions in
# Mongo.
File().save(datafile)
try:
datafile = Upload().uploadFromFile(
io.BytesIO(dataStored), size=len(dataStored),
name='_largeImageThumbnail', parentType='item', parent=item,
user=None, mimeType=imageMime, attachParent=True)
if not len(dataStored) and 'received' in datafile:
datafile = Upload().finalizeUpload(
datafile, Assetstore().load(datafile['assetstoreId']))
datafile.update({
'isLargeImageThumbnail' if not pickleCache else 'isLargeImageData': True,
'thumbnailKey': key,
})
# Ideally, we would check that the file is still wanted before
# we save it. This is probably impossible without true
# transactions in Mongo.
File().save(datafile)
except (GirderException, PermissionError):
logger.warning('Could not cache data for large image')
return imageData, imageMime

def removeThumbnailFiles(self, item, keep=0, sort=None, imageKey=None, **kwargs):
Expand Down

0 comments on commit 619fcc9

Please sign in to comment.