From ce055e7264946a5331d9ba3b931a1aec0329af06 Mon Sep 17 00:00:00 2001 From: meetul Date: Wed, 14 Feb 2024 09:21:32 +0530 Subject: [PATCH] add constant for query limit date --- src/constants.ts | 5 +++++ .../createRecurringEventInstancesDuringQuery.ts | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 8745ce129a..c3d1f596f7 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -538,6 +538,11 @@ export const RECURRING_EVENT_INSTANCES_WEEKLY_LIMIT = 2; export const RECURRING_EVENT_INSTANCES_MONTHLY_LIMIT = 5; export const RECURRING_EVENT_INSTANCES_YEARLY_LIMIT = 10; +// recurrence rules query date limit in years +// i.e. query limit date to find the pending recurrence patterns +// and then generate new instances ahead of this date +export const RECURRING_EVENT_INSTANCES_QUERY_LIMIT = 1; + // recurring event days export const RECURRENCE_WEEKDAYS = [ "MONDAY", diff --git a/src/helpers/event/createEventHelpers/createRecurringEventInstancesDuringQuery.ts b/src/helpers/event/createEventHelpers/createRecurringEventInstancesDuringQuery.ts index 225608165d..ca3cad5529 100644 --- a/src/helpers/event/createEventHelpers/createRecurringEventInstancesDuringQuery.ts +++ b/src/helpers/event/createEventHelpers/createRecurringEventInstancesDuringQuery.ts @@ -9,6 +9,7 @@ import { import { session } from "../../../db"; import type { Recurrance } from "../../../types/generatedGraphQLTypes"; import type { InterfaceGenerateRecurringInstancesData } from "../recurringEventHelpers/generateRecurringEventInstances"; +import { RECURRING_EVENT_INSTANCES_QUERY_LIMIT } from "../../../constants"; /** * This function creates the instances of a recurring event upto a certain date during queries. @@ -26,12 +27,15 @@ export const createRecurringEventInstancesDuringQuery = async ( ): Promise => { // get the current calendar date in UTC midnight const calendarDate = convertToUTCDate(new Date()); - const queryLimitDate = addYears(calendarDate, 2); + const queryUptoDate = addYears( + calendarDate, + RECURRING_EVENT_INSTANCES_QUERY_LIMIT + ); // get the recurrenceRules const recurrenceRules = await RecurrenceRule.find({ organizationId, - latestInstanceDate: { $lt: queryLimitDate }, + latestInstanceDate: { $lt: queryUptoDate }, }).lean(); await Promise.all( @@ -66,7 +70,7 @@ export const createRecurringEventInstancesDuringQuery = async ( recurrenceRule.recurrenceRuleString, recurrenceStartDate, recurrenceRule.endDate, - calendarDate + queryUptoDate ); // find out how many instances following the recurrence rule already exist and how many more to generate