-
Notifications
You must be signed in to change notification settings - Fork 43
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
Create new large images for each item in a folder #1572
Conversation
…sh commits from master # dependency-type: direct:production #update-type: version-update:semver-major
result['largeImagesRemovedAndRecreated'] += 1 | ||
else: | ||
largeImageFileId = None | ||
files = list(Item().childFiles(item=item)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a limit=2
to the childFiles
call; we don't want to retrieve any more data than needed for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Changed that in this commit.
files = list(Item().childFiles(item=item)) | ||
if len(files) == 1: | ||
largeImageFileId = str(files[0]['_id']) | ||
ImageItem().createImageItem(item, File().load(user=user, id=largeImageFileId), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines can be simplied -- there is no need to load the file; we already have it. That ism you can get rid of largeImageFileId = str(files[0]['_id'])
and just do ImageItem().createImageItem(item, files[0], createJob=createJobs, localJob=localJobs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's much cleaner. Change made here.
I'd like to add a basic test of this. Something like
could be added to the A better test set would also create a subfolder and put a file there to test recursion, and would test running the process a second time doesn't create any large images since they already exist and are fine. |
user = self.getCurrentUser() | ||
createJobs = params.get('createJobs') | ||
if createJobs: | ||
createJobs = 'always' or True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a fragment from the item tiles endpoint with the force flag. If this is a function renaming from the force flag, then it should go back to being called force for consistency and then internally, this goes back to createJob='always' if self.boolParam('force', params, default=False) else True
. The third state (don't use a job no matter what) would require the endpoint's parameter to accept three states (functionally these are 'always'
, never (False), and if-needed (True)).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order for the parameter to accept the three states, do you think it's best to make a string parameter and change createJobs accordingly? Should the flag still be called force?
ImageItem().getMetadata(item) | ||
result['itemsSkipped'] += 1 | ||
continue | ||
except TileSourceError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need to catch both TileSourceError
and KeyError
. Specifically, if a source has been uninstalled, it will throw a KeyError
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Change made here.
assert resp.json['largeImagesCreated'] == 1 | ||
item = Item().load(itemId, user=admin) | ||
# Check that this item became a large image again | ||
assert 'largeImage' in item |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's extend this to test a few more conditions. Continuing within this function:
# Hitting the endpoint again should skip the item
resp = server.request(
method='PUT', path=f'/large_image/folder/{folderId}/tiles', user=admin)
assert utilities.respStatus(resp) == 200
assert resp.json['itemsSkipped'] == 1
# If the item's source isn't working, it should be recreated.
item['largeImage']['sourceName'] = 'unknown'
Item().updateItem(item)
resp = server.request(
method='PUT', path=f'/large_image/folder/{folderId}/tiles', user=admin)
assert utilities.respStatus(resp) == 200
assert resp.json['largeImagesRemovedAndRecreated'] == 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function modified here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, There are two minor tasks in #1139 that can be in future PRs (the ability to delete pending creation jobs and the ability to force un/redoing existing large images based on a filter).
This adds an endpoint that creates large images for an entire folder, as mentioned here. It iterates through the folder's items, skips over items with a large image already and creates a large image for the items without one. It has several options, one that recurses child folders, a second that creates a job for each large image item, and another that makes the jobs local.
This does not yet retry creating large images for items with an unfinished large image, but seemed to be a good start.