Skip to content

Commit

Permalink
#318, #325 misc optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Aug 11, 2017
1 parent 0f5bd6d commit 14b3857
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ public List<TicketCategoryModification> getCategoriesWithTickets(@PathVariable("
Event event = loadEvent(eventName, principal);
return eventStatisticsManager.loadTicketCategoriesWithStats(event).stream()
.filter(tc -> !tc.getTickets().isEmpty())
.map(tc -> TicketCategoryModification.fromTicketCategory(tc.getTicketCategory(), ticketCategoryDescriptionRepository.findByTicketCategoryId(tc.getId()), event.getZoneId()))
.map(tc -> TicketCategoryModification.fromTicketCategory(tc.getTicketCategory(), tc.getDescription(), event.getZoneId()))
.collect(toList());
}

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/alfio/manager/EventStatisticsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public EventWithAdditionalInfo getEventWithAdditionalInfo(String eventName, Stri
BigDecimal grossIncome = MonetaryUtil.centsToUnit(eventRepository.getGrossIncome(event.getId()));

List<TicketCategory> ticketCategories = loadTicketCategories(event);

List<Integer> ticketCategoriesIds = ticketCategories.stream().map(TicketCategory::getId).collect(Collectors.toList());

Map<Integer, Map<String, String>> descriptions = ticketCategoryDescriptionRepository.descriptionsByTicketCategory(ticketCategoriesIds);
Expand All @@ -120,10 +119,15 @@ public EventWithAdditionalInfo getEventWithAdditionalInfo(String eventName, Stri
}

public List<TicketCategoryWithStatistic> loadTicketCategoriesWithStats(Event event) {

List<TicketCategory> categories = loadTicketCategories(event);
List<Integer> ticketCategoriesIds = categories.stream().map(TicketCategory::getId).collect(Collectors.toList());
Map<Integer, Map<String, String>> descriptions = ticketCategoryDescriptionRepository.descriptionsByTicketCategory(ticketCategoriesIds);
Map<Integer, List<SpecialPrice>> specialPrices = specialPriceRepository.findAllByCategoriesIdsMapped(ticketCategoriesIds);

return loadTicketCategories(event).stream()
.map(tc -> new TicketCategoryWithStatistic(tc, loadModifiedTickets(tc.getEventId(), tc.getId()),
specialPriceRepository.findAllByCategoryId(tc.getId()), event,
ticketCategoryDescriptionRepository.descriptionForTicketCategory(tc.getId())))
specialPrices.get(tc.getId()), event, descriptions.get(tc.getId())))
.sorted()
.collect(toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public int getPriceInCents() {
return Optional.ofNullable(price).map(MonetaryUtil::unitToCents).orElse(0);
}

public static TicketCategoryModification fromTicketCategory(TicketCategory tc, List<TicketCategoryDescription> ticketCategoryDescriptions, ZoneId zoneId) {
public static TicketCategoryModification fromTicketCategory(TicketCategory tc, Map<String, String> ticketCategoryDescriptions, ZoneId zoneId) {
return new TicketCategoryModification(tc.getId(),
tc.getName(),
tc.getMaxTickets(),
DateTimeModification.fromZonedDateTime(tc.getInception(zoneId)),
DateTimeModification.fromZonedDateTime(tc.getExpiration(zoneId)),
ticketCategoryDescriptions.stream().collect(Collectors.toMap(TicketCategoryDescription::getLocale, TicketCategoryDescription::getDescription)),
ticketCategoryDescriptions,
tc.getPrice(),
tc.isAccessRestricted(), "", tc.isBounded());
}
Expand Down

0 comments on commit 14b3857

Please sign in to comment.