Skip to content

Commit

Permalink
๐Ÿ› fix(getEvent.ts): add caching options to improve performance and reโ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆduce API calls

๐Ÿ› fix(getEventPasses.ts): add caching options to improve performance and reduce API calls
๐Ÿ› fix(event.query.gql): remove @cached directive as it is not needed
๐Ÿ› fix(eventPass.query.gql): remove @cached directive as it is not needed
  • Loading branch information
sebpalluel committed Jan 29, 2024
1 parent 1ae6339 commit c590314
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
13 changes: 8 additions & 5 deletions libs/features/organizer/event-api/src/lib/getEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ interface GetEventProps {
}

export const getEvent = cache(async ({ eventSlug, locale }: GetEventProps) => {
const data = await adminSdk.GetEvent({
slug: eventSlug,
locale: locale as Locale,
stage: env.HYGRAPH_STAGE as Stage,
});
const data = await adminSdk.GetEvent(
{
slug: eventSlug,
locale: locale as Locale,
stage: env.HYGRAPH_STAGE as Stage,
},
{ next: { revalidate: 60 } },
);
const event = data?.event;
if (event?.eventParameters?.status === EventStatus_Enum.Published)
return event;
Expand Down
13 changes: 8 additions & 5 deletions libs/features/organizer/event-api/src/lib/getEventPasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ interface GetEventPassesProps {

export const getEventPasses = cache(
async ({ eventSlug, locale }: GetEventPassesProps) => {
const data = await adminSdk.GetEventParametersAndEventPasses({
eventSlug: eventSlug,
locale: locale as Locale,
stage: env.HYGRAPH_STAGE as Stage,
});
const data = await adminSdk.GetEventParametersAndEventPasses(
{
eventSlug: eventSlug,
locale: locale as Locale,
stage: env.HYGRAPH_STAGE as Stage,
},
{ next: { revalidate: 60 } },
);
const event = data?.event;
if (event?.eventParameters?.status === EventStatus_Enum.Published)
return data;
Expand Down
6 changes: 3 additions & 3 deletions libs/gql/admin/api/src/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ ${KycFieldsFragmentDoc}`;
}
`;
const GetEventDocument = `
query GetEvent($slug: String!, $locale: Locale!, $stage: Stage!) @cached {
query GetEvent($slug: String!, $locale: Locale!, $stage: Stage!) {
event(where: {slug: $slug}, locales: [$locale, en], stage: $stage) {
...EventListFields
description {
Expand Down Expand Up @@ -539,7 +539,7 @@ ${KycFieldsFragmentDoc}`;
${EventParametersMinimalFieldsFragmentDoc}
${EventDateLocationsFieldsFragmentDoc}`;
const GetEventWithPassesDocument = `
query GetEventWithPasses($slug: String!, $locale: Locale!, $stage: Stage!) @cached {
query GetEventWithPasses($slug: String!, $locale: Locale!, $stage: Stage!) {
event(where: {slug: $slug}, locales: [$locale, en], stage: $stage) {
id
slug
Expand Down Expand Up @@ -698,7 +698,7 @@ ${PassPricingFieldsFragmentDoc}`;
}
`;
const GetEventParametersAndEventPassesDocument = `
query GetEventParametersAndEventPasses($eventSlug: String!, $locale: Locale!, $stage: Stage!) @cached {
query GetEventParametersAndEventPasses($eventSlug: String!, $locale: Locale!, $stage: Stage!) {
eventPasses(
where: {event: {slug: $eventSlug}}
locales: [$locale, en]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
query GetEvent($slug: String!, $locale: Locale!, $stage: Stage!) @cached {
query GetEvent($slug: String!, $locale: Locale!, $stage: Stage!) {
event(where: { slug: $slug }, locales: [$locale, en], stage: $stage) {
...EventListFields
description {
Expand Down Expand Up @@ -35,8 +35,7 @@ query GetEvent($slug: String!, $locale: Locale!, $stage: Stage!) @cached {
}
}

query GetEventWithPasses($slug: String!, $locale: Locale!, $stage: Stage!)
@cached {
query GetEventWithPasses($slug: String!, $locale: Locale!, $stage: Stage!) {
event(where: { slug: $slug }, locales: [$locale, en], stage: $stage) {
id
slug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ query GetEventParametersAndEventPasses(
$eventSlug: String!
$locale: Locale!
$stage: Stage!
) @cached {
) {
eventPasses(
where: { event: { slug: $eventSlug } }
locales: [$locale, en]
Expand Down

0 comments on commit c590314

Please sign in to comment.