Skip to content

feat: Parallelize event page fetch #4400

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
merged 2 commits into from
May 23, 2020
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions app/components/public/ticket-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,23 @@ export default Component.extend(FormMixin, {
this.set('invalidPromotionalCode', true);
}
try {
let discountCode = await this.store.queryRecord('discount-code', { eventIdentifier: this.event.id, code: this.promotionalCode });
let discountCodeEvent = await discountCode.get('event');
const discountCode = await this.store.queryRecord('discount-code', { eventIdentifier: this.event.id, code: this.promotionalCode, include: 'event,tickets' });
const discountCodeEvent = await discountCode.event;
if (this.currentEventIdentifier === discountCodeEvent.identifier) {
let discountType = discountCode.get('type');
let discountValue = discountCode.get('value');
const discountType = discountCode.type;
const discountValue = discountCode.value;
this.order.set('discountCode', discountCode);
let tickets = await discountCode.get('tickets');
const tickets = await discountCode.tickets;
tickets.forEach(ticket => {
let ticketPrice = ticket.get('price');
let taxRate = ticket.get('event.tax.rate');
let discount = discountType === 'amount' ? Math.min(ticketPrice, discountValue) : ticketPrice * (discountValue / 100);
const ticketPrice = ticket.price;
const taxRate = ticket.get('event.tax.rate');
const discount = discountType === 'amount' ? Math.min(ticketPrice, discountValue) : ticketPrice * (discountValue / 100);
ticket.set('discount', discount);
if (taxRate && !this.showTaxIncludedMessage) {
let ticketPriceWithTax = (ticketPrice - ticket.discount) * (1 + taxRate / 100);
const ticketPriceWithTax = (ticketPrice - ticket.discount) * (1 + taxRate / 100);
ticket.set('ticketPriceWithTax', ticketPriceWithTax);
} else if (taxRate && this.showTaxIncludedMessage) {
let includedTaxAmount = (taxRate * (ticketPrice - discount)) / (100 + taxRate);
const includedTaxAmount = (taxRate * (ticketPrice - discount)) / (100 + taxRate);
ticket.set('includedTaxAmount', includedTaxAmount);
}
this.discountedTickets.addObject(ticket);
Expand Down
79 changes: 43 additions & 36 deletions app/routes/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,58 @@ import Route from '@ember/routing/route';
import moment from 'moment';
import { set } from '@ember/object';
import ENV from 'open-event-frontend/config/environment';
import { allSettled } from 'rsvp';

@classic
export default class IndexRoute extends Route {
@service
headData;

async model() {
const eventDetails = this.modelFor('public');
return {
event : eventDetails,
tickets : await eventDetails.query('tickets', {
reload: true,
const event = this.modelFor('public');
const ticketsPromise = event.query('tickets', {
filter: [
{
and: [
{
name : 'sales-starts-at',
op : 'le',
val : moment().toISOString()
},
{
name : 'sales-ends-at',
op : 'ge',
val : moment().toISOString()
}
]
}
]
});
const featuredSpeakersPromise = event.query('speakers', {
filter: [
{
name : 'is-featured',
op : 'eq',
val : 'true'
}
],
'page[size]': 0
});
const sponsorsPromise = event.get('sponsors');
const taxPromise = event.get('tax');

filter: [
{
and: [
{
name : 'sales-starts-at',
op : 'le',
val : moment().toISOString()
},
{
name : 'sales-ends-at',
op : 'ge',
val : moment().toISOString()
}
]
}
]
}),
featuredSpeakers: await eventDetails.query('speakers', {
filter: [
{
name : 'is-featured',
op : 'eq',
val : 'true'
}
],
'page[size]': 0
}),
const [tickets, featuredSpeakers, sponsors, tax] = (await allSettled([ticketsPromise, featuredSpeakersPromise, sponsorsPromise, taxPromise]))
.map(result => result.value);

return {
event,
tickets,
featuredSpeakers,

sponsors : await eventDetails.get('sponsors'),
tax : await eventDetails.get('tax'),
order : this.store.createRecord('order', {
event : eventDetails,
sponsors,
tax,
order: this.store.createRecord('order', {
event,
user : this.authManager.currentUser,
tickets : []
}),
Expand Down