Skip to content

Optimize Harvests with memoization and fragment caching#4595

Merged
CloCkWeRX merged 3 commits intodevfrom
optimize-harvests-caching-memoization-9176733581563564983
Apr 28, 2026
Merged

Optimize Harvests with memoization and fragment caching#4595
CloCkWeRX merged 3 commits intodevfrom
optimize-harvests-caching-memoization-9176733581563564983

Conversation

@CloCkWeRX
Copy link
Copy Markdown
Collaborator

Implemented memoization for display and calculation methods in the Harvest model and PredictHarvest concern to reduce redundant processing. Added fragment caching for harvest-related partials, including a strategy to prevent stale relative time strings by including the current date in the cache key.


PR created automatically by Jules for task 9176733581563564983 started by @CloCkWeRX

- Memoize display methods in `Harvest` model.
- Memoize calculation methods in `PredictHarvest` concern using `defined?` for nil safety.
- Add fragment caching to `app/views/harvests/_popover.html.haml`.
- Add fragment caching to `app/views/crops/_harvests.html.haml` with daily expiration for relative time strings.

Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Comment thread app/views/crops/_harvests.html.haml Outdated
@@ -6,13 +6,14 @@
- unless crop.harvests.empty?
%ul.list-group.list-group-flush
- Harvest.where(crop: crop).includes(:owner).order(harvested_at: :desc).limit(3).each do |harvest|
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jules cache this query as well, unless the whole partial is already cached

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've wrapped the query in Rails.cache.fetch with a key that includes the crop and the current date (to keep relative time strings accurate). I've also kept the inner fragment cache for each individual harvest item for maximum reuse across different views.

google-labs-jules Bot and others added 2 commits April 28, 2026 03:16
- Memoize display methods in `Harvest` model.
- Memoize calculation methods in `PredictHarvest` concern using `defined?` for nil safety.
- Add fragment caching to `app/views/harvests/_popover.html.haml`.
- Add fragment caching and query caching to `app/views/crops/_harvests.html.haml` with daily expiration for relative time strings.

Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com>
@CloCkWeRX CloCkWeRX merged commit dfac51e into dev Apr 28, 2026
16 checks passed
@CloCkWeRX CloCkWeRX deleted the optimize-harvests-caching-memoization-9176733581563564983 branch April 28, 2026 03:50
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

Successfully merging this pull request may close these issues.

1 participant