I have a recurring events application, each event can have multiple recurrence patterns (RFC5545), a date can be in different recurrence patterns so I have added an autofield integer to prioritize the most recently added recurrences, each recurrence pattern has a max seat capacity.
So far so good the problem starts when I need to check all the dates that have seats available for the next 365 days:
I would have to check each date against a recurrence rule/pattern and finding that date get the capacity associated with the recurrence.
maybe an example pseudocode is better understood than my English. ex.:
reseved = "info with the number of person by each date reserved"
patterns = {
0:["RRULE:FREQ=DAILY;", "max 10 person"],
1:["RRULE:FREQ=MONTLY;UNTIL=2021-10-10", "max 15 person"],
2:["RRULE:FREQ=DAILY;UNTIL=2021-06-15", "max 25 person"]
}
patterns_ordered = patterns.order_by["index"]
date = "2021-01-01"
last_date = "2021-01-01" + 365 days
while date < laste_date:
for rule in patterns_ordered:
If date in rule and rule.capacity > number_reserved in date:
save date in array with it's availibility.
this is very costly in terms of performance, I have tried to check month after month while the user is browsing a calendar. it is very expensive and the server is overloaded with the number of ajax calls.
more information about my model class:
class Event(models.Model):
e_name = CharField
e_description = TexField
class EventRecurrence(models.Model):
event = ForeignKey(to=Event)
rfc_pattern = CharField #with rfc ical validation
max_guest = PositiveIntegerField
index = OrderedPositiveIntegerField # an autofield based in event
clas Reservation(models.Model):
date = DateField # date reserved
passengers = PositiveIntegerField
amount = DecimalField
event = ForeignKey(to=Event)
...........