Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last_occurrence #117

Closed
dlee opened this issue Nov 12, 2012 · 7 comments
Closed

Add last_occurrence #117

dlee opened this issue Nov 12, 2012 · 7 comments

Comments

@dlee
Copy link

dlee commented Nov 12, 2012

We want to store schedules in the database, and require a way to quickly query whether a schedule (and all its occurrences) overlaps a certain time span. In order to do this, we want to store the beginning/end boundaries of the schedule.

Getting the beginning boundary is easy, since it's just the schedule.start_time, but there is no way to get the last occurrence (our non-performant workaround is to do schedule.all_occurrences.last). It would be great to have a schedule.last_occurrence.

@forrest
Copy link

forrest commented Nov 12, 2012

The internal code iterates through all occurrence until it hits the end point. As a result, a method could be added which performs your approach, but there is no way to just arrive at the last date.

Seeing as all calculations are performed in memory, what kind of delays are you seeing from the execution of schedule.all_occurrences.last? There are a number of locations where performance for schedules containing a large number of rules could be improved, if performance becomes a real issue.

@dlee
Copy link
Author

dlee commented Nov 13, 2012

The internal code iterates through all occurrence until it hits the end point. As a result, a method could be added which performs your approach, but there is no way to just arrive at the last date.

Are you sure "there is no way" to calculate the last date without iterating through all occurrences? I would assume there's a programmatic way to determine the last occurrence without doing the brute-force approach.
Seeing as all calculations are performed in memory, what kind of delays are you seeing from the execution of schedule.all_occurrences.last? There are a number of locations where performance for schedules containing a large number of rules could be improved, if performance becomes a real issue.

The delays are simply that it returns slowly. It's not slow enough to notice if you calculate one last occurrence, but it's noticeable when you have to calculate the last occurrence for many schedules.

@forrest
Copy link

forrest commented Nov 13, 2012

I'm pretty sure. Because there are so many possible rules, and the ability to have multiple rule on a single schedule, it can become extremely complicated. DST, variable month lengths, leap years, etc make it additionally complex. Often, you must know when the previous item is to calculate the next occurrence.

I'm not the library maintainer/author however, so @seejohnrun can give you a better answer.

@ericcf
Copy link

ericcf commented Nov 19, 2012

As a workaround, you could add a column in the database for the last_occurrence_at and cache the value up front when the rules change.

@dlee
Copy link
Author

dlee commented Nov 19, 2012

Yup, that's what I'm already doing. I just wanted to make the initial calculation fast as well.

On Nov 19, 2012, at 9:44 AM, Eric Carty-Fickes [email protected] wrote:

As a workaround, you could add a column in the database for the last_occurrence_at and cache the value up front when the rules change.


Reply to this email directly or view it on GitHub.

@avit
Copy link
Collaborator

avit commented Feb 14, 2013

Keep in mind that a rule must be terminating? == true for it to have a last occurrence, it would just return nil otherwise.

It should work if we make it possible to jump backwards from a rule's until time, but currently everything is designed around jumping forward and it'll require some work to change that.

For rules limited by count, it won't be so easy to optimize.

@seejohnrun
Copy link
Collaborator

count is my nightmare :)

@avit avit closed this as completed in dbe1938 May 21, 2013
rlivsey pushed a commit to rlivsey/ice_cube that referenced this issue Jun 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants