Skip to content

Commit

Permalink
#4107 Performance improvements for column sorting (sakaiproject#4108)
Browse files Browse the repository at this point in the history
  • Loading branch information
plukasew authored and steveswinsburg committed Mar 18, 2017
1 parent 9939ea3 commit 7a7f031
Showing 1 changed file with 26 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.stream.Collectors;

import javax.xml.bind.JAXBException;
import lombok.RequiredArgsConstructor;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.CompareToBuilder;
Expand Down Expand Up @@ -683,20 +684,19 @@ public List<GbStudentGradeInfo> buildGradeMatrix(final List<Assignment> assignme
// this gives us our base list and will be sorted as per our desired
// sort method
final List<User> students = getUsers(studentUuids);
if (settings.getStudentSortOrder() != null || settings.getNameSortOrder() != null) {
stopwatch.timeWithContext("buildGradeMatrix", "getUsers", stopwatch.getTime());
if (settings.getStudentSortOrder() != null) {

if (settings.getNameSortOrder() == GbStudentNameSortOrder.FIRST_NAME) {
Collections.sort(students, new FirstNameComparator());
} else {
Collections.sort(students, new LastNameComparator());
}
Comparator<User> comp = GbStudentNameSortOrder.FIRST_NAME == settings.getNameSortOrder() ?
new FirstNameComparator() : new LastNameComparator();

if (settings.getStudentSortOrder() != null &&
settings.getStudentSortOrder().equals(SortDirection.DESCENDING)) {
if (SortDirection.DESCENDING == settings.getStudentSortOrder()) {

Collections.reverse(students);
comp = Collections.reverseOrder(comp);
}
Collections.sort(students, comp);
}
stopwatch.timeWithContext("buildGradeMatrix", "sortUsers", stopwatch.getTime());

// get course grades
final Map<String, CourseGrade> courseGrades = getCourseGrades(studentUuids);
Expand Down Expand Up @@ -988,46 +988,42 @@ public List<GbStudentGradeInfo> buildGradeMatrix(final List<Assignment> assignme

// sort the matrix based on the supplied assignment sort order (if any)
if (settings.getAssignmentSortOrder() != null) {
final AssignmentGradeComparator comparator = new AssignmentGradeComparator();
comparator.setAssignmentId(settings.getAssignmentSortOrder().getAssignmentId());
Comparator<GbStudentGradeInfo> comparator = new AssignmentGradeComparator(settings.getAssignmentSortOrder().getAssignmentId());

final SortDirection direction = settings.getAssignmentSortOrder().getDirection();

// sort
Collections.sort(items, comparator);

// reverse if required
if (direction == SortDirection.DESCENDING) {
Collections.reverse(items);
comparator = Collections.reverseOrder(comparator);
}
// sort
Collections.sort(items, comparator);
}
stopwatch.timeWithContext("buildGradeMatrix", "matrix sorted by assignment", stopwatch.getTime());

// sort the matrix based on the supplied category sort order (if any)
if (settings.getCategorySortOrder() != null) {
final CategorySubtotalComparator comparator = new CategorySubtotalComparator();
comparator.setCategoryId(settings.getCategorySortOrder().getCategoryId());
Comparator comparator = new CategorySubtotalComparator(settings.getCategorySortOrder().getCategoryId());

final SortDirection direction = settings.getCategorySortOrder().getDirection();

// sort
Collections.sort(items, comparator);

// reverse if required
if (direction == SortDirection.DESCENDING) {
Collections.reverse(items);
comparator = Collections.reverseOrder(comparator);
}
// sort
Collections.sort(items, comparator);

}
stopwatch.timeWithContext("buildGradeMatrix", "matrix sorted by category", stopwatch.getTime());

if (settings.getCourseGradeSortOrder() != null) {
// sort
Collections.sort(items, new CourseGradeComparator(getGradebookSettings()));

Comparator<GbStudentGradeInfo> comp = new CourseGradeComparator(getGradebookSettings());
// reverse if required
if (settings.getCourseGradeSortOrder() == SortDirection.DESCENDING) {
Collections.reverse(items);
comp = Collections.reverseOrder(comp);
}
// sort
Collections.sort(items, comp);
}
stopwatch.timeWithContext("buildGradeMatrix", "matrix sorted by course grade", stopwatch.getTime());

Expand Down Expand Up @@ -2010,10 +2006,10 @@ public boolean isFinalGradeModeEnabled() {
* has.
*
*/
@RequiredArgsConstructor
class AssignmentGradeComparator implements Comparator<GbStudentGradeInfo> {

@Setter
private long assignmentId;
private final long assignmentId;

@Override
public int compare(final GbStudentGradeInfo g1, final GbStudentGradeInfo g2) {
Expand All @@ -2036,10 +2032,10 @@ public int compare(final GbStudentGradeInfo g1, final GbStudentGradeInfo g2) {
* Note that this must have the categoryId set into it so we can extract the appropriate grade entry from the map that each student has.
*
*/
@RequiredArgsConstructor
class CategorySubtotalComparator implements Comparator<GbStudentGradeInfo> {

@Setter
private long categoryId;
private final long categoryId;

@Override
public int compare(final GbStudentGradeInfo g1, final GbStudentGradeInfo g2) {
Expand Down

0 comments on commit 7a7f031

Please sign in to comment.