Skip to content

Add Ransack 4.2 support#5853

Merged
tvdeyen merged 3 commits intosolidusio:mainfrom
tvdeyen:ransack-4.2
Sep 13, 2024
Merged

Add Ransack 4.2 support#5853
tvdeyen merged 3 commits intosolidusio:mainfrom
tvdeyen:ransack-4.2

Conversation

@tvdeyen
Copy link
Copy Markdown
Member

@tvdeyen tvdeyen commented Sep 12, 2024

Summary

In #5395 we introduced a custom Ransacker to allow filtering products by their variants option values in the new admin interface.

This ransacker is broken in latest Ransack v4.2 and overly complicated. By introducing a option_values association to products, that does the same join over variants_including_master and their distinct option_values we can use a normal Ransack search instead.

Quoting the Ransack documentation:

"Ransackers, like scopes, are not a cure-all. Many use cases can be better solved with a standard Ransack search on a dedicated database search field, which is faster, index-able, and scales better than converting/ransacking data on the fly."

This also makes it possible to address N+1 query that can get very nasty with a list of many products with lots of variants.

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

We introduced a custom Ransacker to allow filtering producs by
their variants option values in the new admin interface.

This ransacker is broken in latest Ransack v4.2 and overly
complicated.  By introducing a option_values association to
products, that does the same join over variants_including_master
and their distinct option_values we can use normal ransack search.

Quoting the Ransack documentation:

> "Ransackers, like scopes, are not a cure-all. Many use cases can be better solved with a standard Ransack search on a dedicated database search field, which is faster, index-able, and scales better than converting/ransacking data on the fly."
Now that we removed the broken ransacker in previous commit,
we can allow Ransack v4.2 - with Rails 7.2 support - again.
@tvdeyen tvdeyen self-assigned this Sep 12, 2024
@github-actions github-actions Bot added changelog:solidus_core Changes to the solidus_core gem changelog:solidus_admin labels Sep 12, 2024
@tvdeyen tvdeyen changed the title Ransack 4.2 Add Ransack 4.2 support Sep 12, 2024
@tvdeyen
Copy link
Copy Markdown
Member Author

tvdeyen commented Sep 12, 2024

Thinking about back porting this to 4.3 and 4.2

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.23%. Comparing base (a791a5f) to head (ae69534).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5853      +/-   ##
==========================================
- Coverage   89.24%   89.23%   -0.01%     
==========================================
  Files         753      752       -1     
  Lines       17519    17508      -11     
==========================================
- Hits        15635    15624      -11     
  Misses       1884     1884              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tvdeyen tvdeyen marked this pull request as ready for review September 12, 2024 08:30
@tvdeyen tvdeyen requested a review from a team as a code owner September 12, 2024 08:30
@tvdeyen tvdeyen removed their assignment Sep 12, 2024
@tvdeyen tvdeyen added backport-v4.2 Backport this pull-request to v4.2 backport-v4.3 Backport this pull-request to v4.3 labels Sep 12, 2024
We do not use the custom ransacker this was necessary for
@tvdeyen tvdeyen mentioned this pull request Sep 12, 2024
3 tasks
Copy link
Copy Markdown
Contributor

@MadelineCollier MadelineCollier left a comment

Choose a reason for hiding this comment

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

Nice work, thanks! 🎉

@tvdeyen tvdeyen merged commit 0f77e8b into solidusio:main Sep 13, 2024
@tvdeyen tvdeyen deleted the ransack-4.2 branch September 13, 2024 11:52
@github-actions
Copy link
Copy Markdown

💔 All backports failed

Status Branch Result
v4.2 Backport failed because of merge conflicts
v4.3 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

backport --pr 5853

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-v4.2 Backport this pull-request to v4.2 backport-v4.3 Backport this pull-request to v4.3 changelog:solidus_admin changelog:solidus_core Changes to the solidus_core gem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants