Source:
<code>public List<FeedbackSessionAttributes> getAllFeedbackSessionsWithinTimeRange( Instant rangeStart, Instant rangeEnd) { List<FeedbackSessionAttributes> list = new LinkedList<>(); Instant start = rangeStart.minus(Duration.ofHours(25)); Instant end = rangeEnd.plus(Duration.ofHours(25)); List<FeedbackSession> endEntities = load() .filter("endTime >", TimeHelper.convertInstantToDate(start)) .filter("endTime <=", TimeHelper.convertInstantToDate(end)) .list(); List<FeedbackSession> startEntities = load() .filter("startTime >=", TimeHelper.convertInstantToDate(start)) .filter("startTime <", TimeHelper.convertInstantToDate(end)) .list(); List<FeedbackSession> endTimeEntities = new ArrayList<>(endEntities); List<FeedbackSession> startTimeEntities = new ArrayList<>(startEntities); endTimeEntities.removeAll(startTimeEntities); startTimeEntities.removeAll(endTimeEntities); endTimeEntities.addAll(startTimeEntities); for (FeedbackSession feedbackSession : endTimeEntities) { FeedbackSessionAttributes fs = makeAttributes(feedbackSession); Instant fsStart = fs.getStartTime(); Instant fsEnd = fs.getEndTime(); boolean isStartTimeWithinRange = (fsStart.isAfter(rangeStart) || fsStart.equals(rangeStart)) && fsStart.isBefore(rangeEnd); boolean isEndTimeWithinRange = fsEnd.isAfter(rangeStart) && (fsEnd.isBefore(rangeEnd) || fsEnd.equals(rangeEnd)); if (isStartTimeWithinRange || isEndTimeWithinRange) { list.add(fs); } } <START> List<FeedbackSession> sessions = load().list(); <END> for (FeedbackSession session : sessions) { FeedbackSessionAttributes fs = makeAttributes(session); Instant fsResultsVisibleFromTime = fs.getResultsVisibleFromTime(); if ((fsResultsVisibleFromTime.isAfter(rangeStart) || fsResultsVisibleFromTime.equals(rangeStart)) && fsResultsVisibleFromTime.isBefore(rangeEnd)) { list.add(fs); } } return list; }</code><technical_language>This load 30,000 sessions memory. a query resultsVisibleFromTime instead</technical_language>

Target:
public List<FeedbackSessionAttributes> getAllFeedbackSessionsWithinTimeRange( Instant rangeStart, Instant rangeEnd) { List<FeedbackSessionAttributes> list = new LinkedList<>(); Instant start = rangeStart.minus(Duration.ofHours(25)); Instant end = rangeEnd.plus(Duration.ofHours(25)); List<FeedbackSession> endEntities = load() .filter("endTime >", TimeHelper.convertInstantToDate(start)) .filter("endTime <=", TimeHelper.convertInstantToDate(end)) .list(); List<FeedbackSession> startEntities = load() .filter("startTime >=", TimeHelper.convertInstantToDate(start)) .filter("startTime <", TimeHelper.convertInstantToDate(end)) .list(); List<FeedbackSession> endTimeEntities = new ArrayList<>(endEntities); List<FeedbackSession> startTimeEntities = new ArrayList<>(startEntities); endTimeEntities.removeAll(startTimeEntities); startTimeEntities.removeAll(endTimeEntities); endTimeEntities.addAll(startTimeEntities); for (FeedbackSession feedbackSession : endTimeEntities) { FeedbackSessionAttributes fs = makeAttributes(feedbackSession); Instant fsStart = fs.getStartTime(); Instant fsEnd = fs.getEndTime(); boolean isStartTimeWithinRange = (fsStart.isAfter(rangeStart) || fsStart.equals(rangeStart)) && fsStart.isBefore(rangeEnd); boolean isEndTimeWithinRange = fsEnd.isAfter(rangeStart) && (fsEnd.isBefore(rangeEnd) || fsEnd.equals(rangeEnd)); if (isStartTimeWithinRange || isEndTimeWithinRange) { list.add(fs); } } List<FeedbackSession> resultsVisibleEntities = load() .filter("resultsVisibleFromTime >", TimeHelper.convertInstantToDate(start)) .filter("resultsVisibleFromTime <=", TimeHelper.convertInstantToDate(end)) .list(); list.addAll(makeAttributes(resultsVisibleEntities)); return list; }