Skip to content

Commit

Permalink
add constant for query limit date
Browse files Browse the repository at this point in the history
  • Loading branch information
meetulr committed Feb 14, 2024
1 parent 2f5989e commit ce055e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -26,12 +27,15 @@ export const createRecurringEventInstancesDuringQuery = async (
): Promise<void> => {
// 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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ce055e7

Please sign in to comment.