Repository navigation
Require Ransack 6 and keep searches case-insensitive - #6745
scarroll32 wants to merge 1 commit into
Conversation
Ransack 6.0 made `cont`, `start` and `end` case-sensitive on PostgreSQL: they now generate LIKE instead of ILIKE. The admin, backend and API searches all used them, so on PostgreSQL searching for "reason" would stop finding "Good Reason". MySQL and SQLite are unaffected, as their LIKE follows the column collation. Switch every `cont` and `start` search to `i_cont` and `i_start`, which keep the previous behaviour on every database. `i_start` only exists from Ransack 6.0, so Ransack 6 becomes the minimum. Ransack 6.0 supports Ruby 3.2 and Rails 7.2, Solidus's own minimums; Bundler picks 6.1 on Rails 8.1. The `with_all_variant_sku_cont` and `with_kept_variant_sku_cont` product scopes are left as they are: they are Solidus scopes built on Arel's `matches`, which is already case-insensitive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you for this! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6745 +/- ##
=======================================
Coverage 92.68% 92.68%
=======================================
Files 1083 1083
Lines 22018 22018
=======================================
Hits 20407 20407
Misses 1611 1611 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jarednorman
left a comment
There was a problem hiding this comment.
Thanks again for doing this. @solidusio/core-team has some things to think about regarding how we roll this out. If merged, upgrading to Solidus 4.9 will force everyone to jump to major Ransack versions. That's not necessarily a problem, but it means we need to make sure the following gems with include affected Ransack params are ready to handle this update:
- solidus_subscriptions (
user_email_cont) - solidus_reviews (
name_cont,title_cont,review_cont) - solidus_virtual_gift_card (
redemption_code_cont,recipient_email_cont,order_number_cont) - solidus_gdpr (
email_start) - technically solidus_graphql_api, but that's not maintained and should probably be archived. I don't know of any stores using it.
We can take on this work, but it'll require a little coordination on our side.
The only gotcha with the PR itself I found was that MySQL and SQLite SQL does change, contrary to the description. On non-PostgreSQL dialects, Ransack 6 renders i_start as LOWER(col) LIKE 'x%' (ransack-6.0.1/lib/ransack/nodes/condition.rb:357). The old number_start/email_start produced col LIKE 'x%', which can use an index. That affects:
- the backend order filters (
backend_configuration.rb:65-86); - the user pickers (
backend/app/controllers/spree/admin/search_controller.rb:16).
On large MySQL stores these become full scans. Columns with a case-sensitive collation also start matching case-insensitively. Not ideal, but maybe we just have to live with that and stores can customize if it's a perf issue for them?
Summary
Hi! I'm one of the Ransack maintainers.
solidus_corepinsransack ["~> 4.0", "< 5"], so Solidus stores can't upgrade to Ransack 5 or 6. This PR moves Solidus to Ransack 6. Tracked in activerecord-hackery/ransack#1810.Why it's not just a version bump: Ransack 6.0 made
cont,startandendcase-sensitive on PostgreSQL (LIKEinstead ofILIKE); see the upgrade guide. Solidus's admin, backend and API searches use those predicates in about 130 places. Raising the cap alone would quietly make every PostgreSQL store's admin search case-sensitive. For example, the admin feature specs that filter return reasons byreasonstop finding "Good Reason".What changes:
contandstartsearch becomesi_contandi_start: admin index search keys, backend filters and pickers, the backendSearchControllerandTaxonsController,Spree::Core::Search::Variant, the promotions filters, and the JavaScript that buildsq[...]params. These keep the current behaviour on every database. On MySQL and SQLite,LIKEfollows the column collation, as before.ransackbecomes[">= 6.0", "< 7"].i_startonly exists from Ransack 6.0, so Ransack 6 has to be the minimum. 6.0 supports Ruby 3.2 and Rails 7.2, so Solidus drops no Ruby or Rails version. Bundler picks 6.0.x on Rails 7.2 and 8.0, and 6.1.x on Rails 8.1.with_all_variant_sku_contandwith_kept_variant_sku_contare Solidus's own product scopes built on Arel'smatches, which is already case-insensitive, so they're unchanged.name_i_contand explains the difference.For stores: API clients and custom code that send
contorstartwill be case-sensitive on PostgreSQL once Ransack 6 is installed, and should switch to thei_forms. Ransack 5 and 6 have other behaviour changes too (see the upgrade guide). None of them affected Solidus's specs, but they're worth calling out in the release notes. ransack-enum 1.0 uses onlyransackerandRansack::Nodes::Value#cast, which are unchanged.Tested locally on PostgreSQL:
* The first admin run had 9 failures, from feature specs whose URL-encoded queries (
q%5Bname_cont%5D=reason) still usedcont. Those queries now usei_cont, and the affected files pass (56 examples, 0 failures).Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed:
🤖 Generated with Claude Code