問題描述
我正在構建一個日歷網站 (ASP.NET MVC
) 應用程序(想想 Outlook 的簡單版本),我想開始支持重復出現的日歷事件(每月、每年等)
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.
這讓我想到了 Outlook、谷歌郵件等是如何做到這一點的,或者任何其他支持定期日歷項目的服??務.
It got me thinking how outlook, google mail, etc does this or any other service that supports recurring calendar items.
對此有什么建議嗎?
推薦答案
將您的數據分為兩部分:規范"數據(重復規則)和服務"(生成日期;除了重新生成之外只讀).如果規范數據發生更改,請在該點重新生成服務"數據.對于無限重復,保留一些實例并在用完時生成更多實例(例如,如果用戶查看 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).
如果您有無限的處理器速度,您只需要規范數據 - 但實際上,對每個頁面視圖上的所有重復規則進行所有日期/時間處理可能是太費時了……所以你要犧牲一些存儲(和復雜性)來保存重復的計算.與大量事件所需的計算相比,存儲通常非常便宜.如果您只需要存儲事件的日期,那真的非常便宜 - 您可以輕松地使用 4 字節整數來表示日期,然后從中生成完整的日期/時間,假設您重復都是基于日期的.對于基于時間的重復(例如每三個小時"),您可以使用完整的 UTC 瞬間 - 只要您可能需要,8 個字節就可以將其表示為非常精細的分辨率.
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.
您可能還需要能夠逐次添加注釋和例外情況(例如,由于公共假期,今天沒有舉行會議"或移至下午 4 點").當您更改重復時,這變得真的有趣 - 如果您將每個星期一"更改為每個星期二",您是否保留例外情況?當您從每天"變為每周"時,您甚至如何匹配異常?這些不是直接與存儲有關的問題 - 但存儲決策將影響實施您決定的任何策略的難易程度.
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.
這篇關于在構建日歷應用程序時,我應該在我的數據庫中存儲日期或重復規則嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!