如何最好地处理重复日历事件的异常
我正在开展一个需要我实施日历的项目。我正在尝试设计一个非常灵活的系统:可以处理重复事件、重复异常等。我研究了 iCal、Lotus Notes 和 Mozilla 等应用程序的架构,以了解如何着手实施这样一个系统。目前,我无法确定处理重复事件异常的最佳方法。我使用过很多数据库,但没有大量真正优化所有内容的经验,因此我不确定我正在考虑的两种方法中的哪种方法在整体性能和查询/搜索能力方面是最佳的:
- 打破重复事件。因此,更改重复事件的当前行的结束日期,插入例外的新行,并添加另一行继续旧序列。
- 只需添加一个例外即可。因此,添加一个新行,其中包含一些字段,表明它是覆盖。
所以这就是我无法决定的原因。方法一会产生更多的行,因为每次编辑都需要额外的 2 行,而第二种方法只需要一行。另一方面,我认为查找事件的查询会更简单,因此使用第一种方法可能会更快(?)。第二种方法似乎需要在应用程序服务器上进行更多计算,因为一旦获得数据,就必须删除两行的交集。我知道数据库通常是网站的瓶颈,虽然我确信你们很多人都认为这两者都可以,因为您的项目可能永远不会变得足够大,以至于效率差异变得真正重要,但我仍然想实现最佳解决方案。那么你们会选择什么方法,或者会做一些完全不同的事情呢?
另外,作为旁注,我将使用 MySQL 和 PHP。如果您认为还有其他技术更适合于此,特别是在数据库领域,请提及。
谢谢你的建议。
I'm working on a project that will require me to implement a calendar. I'm trying to come up with a system that is very flexible: can handle repeating events, exceptions to repeats, etc. I've looked at the schema for applications like iCal, Lotus Notes, and Mozilla to get an idea of how to go about implementing such a system. Currently I'm having trouble deciding what is the best way to handle exceptions to repeating events. I've used databases quite a bit but don't have a ton of experience with really optimizing everything so I'm not sure which method of the two I'm considering would be optimal in terms of overall performance and ability to query/search:
- Breaking the repeating event. So taking the changing the ending date on the current row for the repeating event, inserting a new row with the exception, and adding another row continuing the old sequence.
- Simply adding an exception. So adding a new row with some field that indicates it as an override.
So here is why I can't decide. Method one will result in a lot more rows since each edit requires 2 extra rows as apposed to only one row by the second method. On the other hand I think the query to find an event would be much simper, and thus possibly faster(?) using the first method. The second method seems like it will require more calculating on the application server since once you get the data you'll have to remove the intersection of the two rows. I know databases are often the bottleneck for websites and while I'm sure a lot of you are thinking either is fine because your project will probably never get large enough for the difference in efficiency to really matter, I'd still like to implement the best solution. So what method would you guys pick, or would you do something completely different?
Also, as a side note I'll be using MySQL and PHP. If there is another technology that you think would be better suited for this, especially in the database area, please mention it.
Thanks for the advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
活动不是永久性的,可能会发生变化或终止。
您应该为事件中的每个日期插入一行,并在编辑重复事件时,提供编辑事件的所有实例或仅编辑一个实例的选项。
执行此操作时,您实际上应该只需要一个额外的字段来指示事件是否处于活动状态。
如果索引正确,这不会对您的查询产生很大的影响。
一个例子是:
在这种情况下,您需要对 event_id 和 active 列建立索引。
Events are not permanent, are subject to change or termination.
You should insert a row for each date in the event and, upon editing a repeated event, give the option to edit all instances of the event or just one.
When doing this, you should really only need an extra field to indicate if the event is active or not.
When properly indexed, this will not make a considerable difference on your queries.
An example would be:
On which case you'd be required to index the event_id and active columns.
我决定只输入一行包含例外的行,并使用代码将它们从重复集中删除。我需要一段时间才能完成它,但我会尝试并记住在完成后将一些性能结果发回此处。
I've decided to just enter a row with the exceptions and use code to remove them from the repeating set. It'll be awhile before I'm done with it but I'll try and remember to post back here with some performance results when it's all done.