Skip to content
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

Performance MetaDataEditor When Selecting Many Images #5122

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -685,15 +685,33 @@ public List<Pair<PhysicalDivision, LogicalDivision>> getSelectedMedia() {

/**
* Checks and returns if consecutive physical divisions in one structure element are selected or not.
*
* <p>Note: This method is called potentially thousands of times when rendering large galleries.</p>
*/
public boolean consecutivePagesSelected() {
if (selectedMedia.isEmpty()) {
return false;
}
int maxOrder = selectedMedia.stream().mapToInt(m -> m.getLeft().getOrder()).max().orElseThrow(NoSuchElementException::new);
int minOrder = selectedMedia.stream().mapToInt(m -> m.getLeft().getOrder()).min().orElseThrow(NoSuchElementException::new);
return selectedMedia.size() - 1 == maxOrder - minOrder
&& selectedMedia.stream().map(Pair::getValue).distinct().count() == 1;

// Check whether the set of selected media all belong to the same logical division, otherwise the selection
// is not consecutive. However, do not use stream().distinct(), which will do pairwise comparisons, which is
// slow for large amounts of selected images. Instead, just check whether the first logical division matches
// all others in a simple loop.
Boolean theSameLogicalDivisions = true;
LogicalDivision firstSelectedMediaLogicalDivison = null;
for (Pair<PhysicalDivision, LogicalDivision> pair : selectedMedia) {
if (Objects.isNull(firstSelectedMediaLogicalDivison)) {
firstSelectedMediaLogicalDivison = pair.getRight();
} else {
if (!Objects.equals(firstSelectedMediaLogicalDivison, pair.getRight())) {
theSameLogicalDivisions = false;
break;
}
}
}
return selectedMedia.size() - 1 == maxOrder - minOrder && theSameLogicalDivisions;
}

void setSelectedMedia(List<Pair<PhysicalDivision, LogicalDivision>> media) {
Expand Down