5
11
Fork
You've already forked tomato
1

Add next occurrence to shift index #111

Merged
edwardloveall merged 1 commit from el-next-shift-occurrence into main 2026年03月09日 15:21:29 +01:00

It's useful when looking at a list of shifts to know when the next time this shift will happen. Because we don't have this information in the database (yet) we have to calculate in ruby, which is generally slow. I was able to speed it up by creating a timeline with every shift in the view, then adding a new method to the timeline that would just get the next occurrence.

Even then, it's still about 3x slower. On my machine I measured ~120ms to load the page without, and ~380ms with. Reasonable, but not ideal. We hope this will get much faster in the future when we can calculate event occurrences in the database itself.

It also presents a problem for events in the far future. To keep the speed reasonable, we only calculate events out by one month. But if an event starts 1 year in the future, we still want to show it's next occurrence. We don't worry about events in the past, and we only support recurring events one month out.

If no next occurrence could be found, we create an occurrence based on the event's starts_at and use that, because that's the next time it will occur. This logic is wrapped up in a helper: link_to_next_occurrence_in_timeline.

It's useful when looking at a list of shifts to know when the next time this shift will happen. Because we don't have this information in the database (yet) we have to calculate in ruby, which is generally slow. I was able to speed it up by creating a timeline with every shift in the view, then adding a new method to the timeline that would just get the next occurrence. Even then, it's still about 3x slower. On my machine I measured ~120ms to load the page without, and ~380ms with. Reasonable, but not ideal. We hope this will get _much_ faster in the future when we can calculate event occurrences in the database itself. It also presents a problem for events in the far future. To keep the speed reasonable, we only calculate events out by one month. But if an event starts 1 year in the future, we still want to show it's next occurrence. We don't worry about events in the past, and we only support recurring events one month out. If no next occurrence could be found, we create an occurrence based on the event's `starts_at` and use that, because that's the next time it will occur. This logic is wrapped up in a helper: `link_to_next_occurrence_in_timeline`.
edwardloveall force-pushed el-next-shift-occurrence from fdff0c6098
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
to 2950dc65f7
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
2026年03月05日 21:59:20 +01:00
Compare
thetizzo left a comment
Copy link

I like this solution for quickly figuring out the next occurrence by using the event instead of calculating out more into the future. Seems about as good as it gets for performance without keeping this in the DB.

I like this solution for quickly figuring out the next occurrence by using the event instead of calculating out more into the future. Seems about as good as it gets for performance without keeping this in the DB.
edwardloveall changed target branch from el-shift-last-updated to main 2026年03月09日 15:13:59 +01:00
Author
Owner
Copy link

Test flakes. Passes locally. Merging

Test flakes. Passes locally. Merging
edwardloveall deleted branch el-next-shift-occurrence 2026年03月09日 15:21:30 +01:00
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rootable/tomato!111
Reference in a new issue
rootable/tomato
No description provided.
Delete branch "el-next-shift-occurrence"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?