问题描述
我有一个重复事件应用程序,每个事件可以有多个重复模式(RFC5545),日期可以采用不同的重复模式,所以我添加了一个自动字段整数来优先考虑最近添加的重复,每次重复模式有一个最大的座位容量。
到目前为止一切顺利,当我需要检查在接下来的 365 天内有可用座位的所有日期时,问题就开始了:
我必须根据重复规则/模式检查每个日期,并找到该日期以获取与重复相关的容量。
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.
这在性能方面的成本非常高,我尝试在用户浏览日历时逐月检查。它非常昂贵,并且服务器因ajax调用次数而过载。
关于我的模型类的更多信息:
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)
...........
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)