-
Notifications
You must be signed in to change notification settings - Fork 551
Fix performance when checking dataset version file count #12494
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
Merged
landreev
merged 10 commits into
develop
from
performance-fix-for-dataset-version-has-files
Jul 1, 2026
+61
−31
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
78c62b4
Fix performance when checking dataset version file count
stevenwinship 1a19e93
fix guest user check
stevenwinship 16765bb
cache hasFiles in perm wrapper
stevenwinship 9c13f0a
cache hasFiles in perm wrapper
stevenwinship fd99707
remove extra calls to get dataset in SearchIncludeFragment
stevenwinship 264c290
remove extra calls to get dataset in SearchIncludeFragment
stevenwinship d3d1414
null entity fix
stevenwinship 0fe658d
null entity fix
stevenwinship 594d637
refactor
stevenwinship 9fac0bb
another refactor
stevenwinship File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
|
|
||
| import edu.harvard.iq.dataverse.authorization.Permission; | ||
| import edu.harvard.iq.dataverse.authorization.groups.impl.builtin.AuthenticatedUsers; | ||
| import edu.harvard.iq.dataverse.authorization.users.GuestUser; | ||
| import edu.harvard.iq.dataverse.authorization.users.User; | ||
| import edu.harvard.iq.dataverse.engine.command.Command; | ||
| import edu.harvard.iq.dataverse.engine.command.DataverseRequest; | ||
|
|
@@ -33,6 +34,9 @@ public class PermissionsWrapper implements java.io.Serializable { | |
| @EJB | ||
| PermissionServiceBean permissionService; | ||
|
|
||
| @EJB | ||
| DatasetVersionServiceBean datasetVersionService; | ||
|
|
||
| @Inject | ||
| DataverseSession session; | ||
|
|
||
|
|
@@ -257,35 +261,42 @@ public boolean canIssueDeleteDatasetCommand(DvObject dvo){ | |
| // PUBLISH DATASET | ||
| public boolean canIssuePublishDatasetCommand(DvObject dvo){ | ||
| User u = session.getUser(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't getUser return a GuestUser? i.e. getAuthenticatedUser() is needed for the check?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
| if (u != null && u.isSuperuser()) { | ||
| if (dvo == null || u == null || u instanceof GuestUser || !(dvo instanceof Dataset)) { | ||
| return false; // guests can not publish | ||
| } | ||
| if (u.isSuperuser()) { | ||
| return true; | ||
| } | ||
| // Return false if dataset has 0 files and user want to 'publish' or 'submit for review' and 'publish dataset requires files' flag is set | ||
| if (dvo.isInstanceofDataset()) { | ||
| Dataverse dv =((Dataset)dvo).getOwner(); | ||
| if (dv != null) { | ||
| List<FileMetadata> metadataList = ((Dataset) dvo).getLatestVersion().getFileMetadatas(); | ||
| if (metadataList.size() == 0 && dv.getEffectiveRequiresFilesToPublishDataset()) { | ||
| return false; | ||
| } | ||
| } | ||
| Dataset ds = (Dataset)dvo; | ||
| Dataverse dv = ds.getOwner(); | ||
| if (dv != null && !datasetVersionHasFiles(ds.getLatestVersion()) && dv.getEffectiveRequiresFilesToPublishDataset()) { | ||
| return false; | ||
| } | ||
| return canIssueCommand(dvo, PublishDatasetCommand.class); | ||
| return canIssueCommand(ds, PublishDatasetCommand.class); | ||
| } | ||
|
|
||
| // SUBMIT DATASET FOR REVIEW | ||
| public boolean canIssueSubmitDatasetForReviewCommand(DvObject dvo){ | ||
| public boolean canIssueSubmitDatasetForReviewCommand(DvObject dvo) { | ||
| User u = session.getUser(); | ||
| if (dvo == null || u == null || u instanceof GuestUser || !(dvo instanceof Dataset)) { | ||
| return false; // guests can not submit for review | ||
| } | ||
| // Return false if dataset has 0 files and user want to 'publish' or 'submit for review' and 'publish dataset requires files' flag is set | ||
| if (dvo.isInstanceofDataset()) { | ||
| Dataverse dv =((Dataset)dvo).getOwner(); | ||
| if (dv != null) { | ||
| List<FileMetadata> metadataList = ((Dataset) dvo).getLatestVersion().getFileMetadatas(); | ||
| if (metadataList.size() == 0 && dv.getEffectiveRequiresFilesToPublishDataset()) { | ||
| return false; | ||
| } | ||
| } | ||
| Dataset ds = (Dataset)dvo; | ||
| Dataverse dv = ds.getOwner(); | ||
| if (dv != null && !datasetVersionHasFiles(ds.getLatestVersion()) && dv.getEffectiveRequiresFilesToPublishDataset()) { | ||
| return false; | ||
| } | ||
| return canIssueCommand(ds, SubmitDatasetForReviewCommand.class); | ||
| } | ||
|
|
||
| // cache the hasFiles in the ds version for performance reasons | ||
| private boolean datasetVersionHasFiles(DatasetVersion dsv) { | ||
| if (dsv.hasFiles() == null) { | ||
| dsv.setHasFiles(datasetVersionService.hasFiles(dsv.getId())); | ||
| } | ||
| return canIssueCommand(dvo, SubmitDatasetForReviewCommand.class); | ||
| return dsv.hasFiles(); | ||
| } | ||
|
|
||
| // For the dataverse_header fragment (and therefore, most of the pages), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 are in the permissionsWrapper class - shouldn't the results also be cached for the life of the bean?
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.
Why would we cache the results? It would change when a file upload completes
Uh oh!
There was an error while loading. Please reload this page.
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.
If caching isn't appropriate, should the method be in the PermissionServiceBean instead? The *Wrapper classes are viewscoped and should just have cached info (probably not enforced). That would make the call accessable via API as well.
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.
Generally, we want everything that is called from JSF
rendered="#{...}"attributes cached (because these are evaluated 7 times). Probably a good idea even when there is no reason to expect the task to be expensive.In this specific case, I am actually not sure off the top of my head about the "would change when a file upload completes"... PermissionsWrapper is
@ViewScoped. Does that mean that it will be a new "View" when the page re-renders itself after an upload completes? Or the same one?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.
Would be easy to test though.
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 - I'm not sure w/o digging - @viewScoped would stay as long as we're just doing ajax updates? We also cache in the DatasetPage at times - that would be a place where the cache could be emptied when a file upload completes.
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.
looked into it some more
From a quick test, caching that info within a View does NOT prevent the page from properly updating itself once one or more files has been uploaded (that re-rendering apparently counts as a new View).
Yes, we DO want to cache this (on top of caching the result of
permissionService...canIssue(command)that we are already doing there). JSF is calling these 2 methods over and over incessantly. Having that NativeQuery executed every time feels wrong.I mentioned in the perf. issue that "The query count goes from 9K+ down to 813 ... This is ~100 more than it has been consistently between the last few releases, but ..." That was from a test of the first iteration of this PR, that was not checking for
|| u instanceof GuestUser. The extra 100 queries were solely from the native query and whatever it instantiated in thedatasetVersionService.hasFiles()performed on the 10 underlying datasets. Re-testing the PR in its current state brought that query count down to 715. (it was 714 in 6.10.1).It will be worse for the dataset page and a logged in browser user.
... So yes, we want to cache.
We'll wrap it up tomorrow.
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.
FYI, this was my quick experiment last night: #12495 (this is a pr into this branch).
I am not positive if this is the best way of handling this.
I'm hoping to be able to focus on other work today.
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.
One last comment:
What's truly annoying, is that the only serious performance degradation this was causing was on the dataverse.xhtml page; where, from what I understand, the check on the number of files may not even be relevant. (the "can publish" check there seems to be a proxy for "can see [some] curation info" - ?)
In dataset.xhtml, where we do need to know whether the dataset has files or not, the original
...Version.getFileMetadatas().size()was NOT even a problem, I don't think - because the filemetadatas are already instantiated, via a monsterfindDeep()query.... we should avoid dumping any excessive amounts of work into this, in other words.
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.
(although
permissionsWrapper.canIssuePublishDatasetCommand()is also called from FilePage.java; it'll definitely help to avoid unnecessarily instantiating all the files in the parent dataset in there as well)