建立一个日历应用程序时,我应该存储在我的数据库日期或复发的规则? [英] Should I store dates or recurrence rules in my database when building a calendar app?

查看:158
本文介绍了建立一个日历应用程序时,我应该存储在我的数据库日期或复发的规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个日历网站( ASP.NET MVC )的应用(想想前景的简版),我想开始支持那些反复出现的(每月日历事件,每年,等)

I am building a calendar website (ASP.NET MVC) application (think simple version of outlook) and i want to start supporting calendar events that are recurring (monthly, yearly, etc)

现在我存储实际日期在我,但我想,如果要弄清楚,复发,是否有意义继续存储日期(有一些明显的截止),或者我应该存储重复选项并生成日期上飞。

right now I am storing actual dates in my but I wanted to figure out if, with recurrence, does it make sense to continue to store dates (with some obvious cutoff), or should I store the recurrence options and generate the dates on the fly.

这让我的思维观,谷歌邮件,等它如何或支持定期日历项目。任何其​​他服务

It got me thinking how outlook, google mail, etc does this or any other service that supports recurring calendar items.

是否有对这个有什么建议?

Are there any suggestions on this?

推荐答案

单独的数据分为两部分:规范的数据(复发规则)和服务(生成日期;从再生只读除外)。如果规范数据的变化,在该点再生服务的数据。对于无限的复发,保持实例的一定数量并产生更多,如果你用完了(例如,如果用户看到他们的日历2020年)。

Separate your data into two parts: the "canonical" data (the recurrence rule) and "serving" (generated dates; read-only aside from regeneration). If the canonical data changes, regenerate the "serving" data at that point. For infinite recurrences, keep some number of instances and generate more if you run out (e.g. if the user looks at their calendar for 2020).

如果你有无限的处理器速度,你只需要规范化数据 - 但在现实中,拼尽全力的日期/时间处理上的所有循环规则的每个的页面视图可能是太费时间......所以你权衡一些存储(和复杂性),以保存重复计算。存储通常是pretty便宜,与大量的事件所需的计算比较。如果你的只有的需要存储的事件的日期,这真的很便宜 - 你可以很容易地使用一个4字节的整数重新present一个日期,然后生成一个完整的日期/时间即,假设你有复发基于所有日期。基于时间的复发(如每三个小时),你可以充分UTC瞬间 - 8个字节将重新present下来到pretty精细的分辨率,只要你有可能需要

If you had infinite processor speed, you'd only need the canonical data - but in reality, doing all the date/time processing for all the recurrence rules on every page view is likely to be too time-consuming... so you trade off some storage (and complexity) to save that repeated computation. Storage is usually pretty cheap, compared with the computation required for a large number of events. If you only need to store the dates of the events, that's really very cheap - you could easily use a 4 byte integer to represent a date, and then generate a complete date/time from that, assuming your recurrences are all date based. For time-based recurrences (e.g. "every three hours") you could full UTC instants - 8 bytes will represent that down to a pretty fine resolution for as long as you're likely to need.

您需要小心维护,虽然有效性 - 如果定期召开的会议修改今天的,并不时的具有改变的过去发生的事情......所以你可能想的的有关于复发时实际发生的典型的只读数据。显然,你不希望保持永远的过去,所以你可能想垃圾回收事件比几年岁以上,取决于您的存储限制。

You need to be careful about maintaining validity though - if a recurring meeting changes today, that doesn't change when it has happened in the past... so you probably want to also have canonical read-only data about when recurrences actually occurred. Obviously you won't want that to keep the past forever, so you probably want to "garbage collect" events more than a few years old, depending on your storage limitations.

您可能还需要添加注释和异常的能力(例如,会议今天不发生因公众假期或移动至下午四时),对每个事件的基础。这成为的真正的乐趣,当你改变了复发 - 如果你改变每周一到每星期二你保持异常或没有?你怎么连当你从天天向上,以每周更换匹配的异常?这些都不是这是直接有关存储的问题 - 但存储决策将影响是多么容易实现你决定什么政策

You may also need the ability to add notes and exceptions (e.g. "meeting doesn't occur today due to a public holiday" or "moved to 4pm") on a per-occurrence basis. That becomes really fun when you change the recurrence - if you change "every Monday" to "every Tuesday" do you keep the exceptions or not? How do you even match up the exceptions when you change from "every day" to "every week"? These aren't questions which are directly about storage - but the storage decisions will affect how easy it is to implement whatever policy you decide on.

这篇关于建立一个日历应用程序时,我应该存储在我的数据库日期或复发的规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆