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

Correctly calculate last_modified_index when the @products scope is u… #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/controllers/spree/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,15 @@ def etag_show
alias product_etag etag_show

def last_modified_index
products_last_modified = @products.maximum(:updated_at)&.utc if @products.respond_to?(:maximum)
if @products.respond_to?(:maximum)
Copy link
Member

Choose a reason for hiding this comment

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

@mrbrdo just wondering - are there any cases where @products won't respond to .maximum?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so (except if @products is nil but I don't think that's an allowed state). I didn't add that if, just kept it from before (was at end of line). And git blame shows it being copied around from another place, I didn't dig deeper.

if max_updated_at = @products.maximum(:updated_at)
if max_updated_at.kind_of?(Hash)
products_last_modified = max_updated_at.values.max&.utc
else
products_last_modified = max_updated_at.utc
end
end
end
current_store_last_modified = current_store.updated_at.utc

[products_last_modified, current_store_last_modified].compact.max
Expand Down