这已是一个 st脚石。 警告:以下不是问题,而是对我所提出问题的解释。 我的问题是——你们有更好的办法这样做吗? 是否有某种共同的技术,使我不熟悉? 象这样的种子是一个棘手的问题。
So you have Task model. You can create tasks, complete them, destroy them. Then you have recurring tasks. It s just like regular task, but it has a recurrence rule attached to it. However, tasks can recur indefinitely — you can go a year ahead in the schedule, and you should see the task show up.
So when a user creates a recurring task, you don t want to build thousands of tasks for hundred years into the future, and save them to database, right? So I started thinking — how do you create them?
一种办法是,在你看到你的时间表时,建立他们。 因此,当用户提前一个月时,将产生任何经常性任务。 当然,这意味着你只能再用任务数据库记录。 每次关于你以往工作的任务的选任活动都必须在具体日期范围内进行,以便在这一日期范围内启动经常性任务。 这是一种维持和业绩的负担,但是可以做到的。
Alright, but how about the original task? Every recurrent task gets associated with the recurrence rule that created it, and every recurrence rule needs to know the original task that started the recurrence. The latter is important, because you need to clone the original task into new dates as the user browses their schedule. I guess doable too.
但是,如果更新原来的任务,情况如何? 这意味着,我们现在随着时间表的推移,我们将产生与修改后任务相左的经常性任务。 这令人不快。 所有暗含的一再重复的任务都应表明原始任务在增加后如何看待。 因此,我们需要单独储存一份原始任务副本,并作此改动,以便重新开展工作。
然而,当用户完成时间表中的任务时,我们如何知道在某个特定时刻是否需要建立新的重复工作? 我们要求复述规则:“如果我今天坚持任务吗?”而且它说是肯定的。 如果现在已经为这一复发工作任务,我们就没有创造。 除用户外,所有冰层也能够简单地删除自动持续重复的任务之一。 在这种情况下,按照我们的逻辑,该系统将重新确定已删除的任务。 不好。 因此,这意味着我们必须保持这项任务的仓储,但把这项任务作为删除的任务加以标示。 Meh.
As I said in the beginning, I want to know if somebody else tackled this problem and can provide architectural advice here. Does it have to be this messy? Is there anything more elegant I m missing?
Update: Since this question is hard to answer perfectly, I will approve the most helpful insight into design/architecture, which has the best helpfulness/trade-offs ratio for this type of problem. It does not have to encompass all the details.