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

Simplify current store selection #2041

Merged
merged 4 commits into from
Jul 12, 2017

Conversation

jhawthorn
Copy link
Contributor

@jhawthorn jhawthorn commented Jun 23, 2017

Previously we selected the current store by pretty hacky means. We took the value of either the SPREE_STORE HTTP header or the domain name, and then selected a store either matching that code or had that value contained anywhere in its url attribute. Failing to find these it falls back to the default store.

Using SPREE_STORE and finding by code is intended to be used with a reverse proxy like nginx, and is a good and powerful way to configure Solidus' multi domain. But it does require extra and very specific
configuration, and isn't overly suitable as a default.

Selecting by url which contains the (header or domain name) value is slow, surprising, and error-prone (think having example.com and ca.example.com).

This commit removes support for the SPREE_STORE header, and allows only one url per-store. Users needing this functionality can replicate it by implementing their own store selector class.

This commit also allows the store selector to perform only a single query to find the current store.


Before

SELECT  "spree_stores".* FROM "spree_stores" WHERE "spree_stores"."code" = ? LIMIT 1
SELECT  "spree_stores".* FROM "spree_stores" WHERE (url like '%localhost%') ORDER BY "spree_stores"."id" ASC LIMIT 1
SELECT  "spree_stores".* FROM "spree_stores" WHERE "spree_stores"."default" = ? ORDER BY "spree_stores"."id" ASC LIMIT 1

After

SELECT  "spree_stores".* FROM "spree_stores"
  WHERE ("spree_stores"."url" = ? OR "spree_stores"."default" = ?)
  ORDER BY "spree_stores"."default" ASC
  LIMIT 1

This is a breaking change, it doesn't have to be, but I think the new behaviour is enough of an improvement that it's worth breaking (with a very clear notice in the CHANGELOG).

I'd like to hear from users running multi-domain stores:

  • Do you use this SPREE_STORE variable?
  • Do you have multiple domains listed in any Store's url attribute (spree_multi_domain used to recommend them newline-separated). If so we may want to add better support for this.

Related to #1971, #2022

cc @kennyadsl

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

👍

Maybe we could extract the previous behavior (mainly the header supporting one) into a second store finder class and still ship it with core, so existing stores can use the old one?

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

This seems to be the best solution to me.

I didn't know multiple store urls could be set. If this feature is used can't we change the query using like (via by_url scope) and support multiline store urls?

@jhawthorn
Copy link
Contributor Author

Maybe we could extract the previous behavior (mainly the header supporting one) into a second store finder class and still ship it with core, so existing stores can use the old one?

Absolutely! Do you think it's reasonable for us to use this as the new default? It should be an improvement for most stores.

I didn't know multiple store urls could be set. If this feature is used can't we change the query using like (via by_url scope) and support multiline store urls?

We could do that, and if we implement a "legacy" store selector class as @tvdeyen suggests, that is what it should do. That said, I'd rather remove that behaviour for this new implementation.

The most glaring issue with the current implementation is that it will incorrectly match ca.example.com for example.com (even if there is a separate example.com store defined). We could change the LIKE query to assume that the stores are newline separated WHERE CONCAT('\n', url, '\n') LIKE '\nexample.com\n', but that's getting really hacky. If multiple store urls are something many of our users need, we should introduce a separate table for it store_urls.

@jhawthorn jhawthorn self-assigned this Jul 5, 2017
@jhawthorn jhawthorn force-pushed the select_store_single_query branch from 7009612 to 288d956 Compare July 6, 2017 22:44
@jhawthorn jhawthorn removed the WIP label Jul 6, 2017
@jhawthorn jhawthorn changed the title [RFC] Simplify current store selection Simplify current store selection Jul 6, 2017
@jhawthorn jhawthorn force-pushed the select_store_single_query branch from 288d956 to 03b16d2 Compare July 11, 2017 18:43
@jhawthorn jhawthorn added this to the 2.3.0 milestone Jul 11, 2017
@jhawthorn jhawthorn force-pushed the select_store_single_query branch from 03b16d2 to 13fc5bf Compare July 11, 2017 23:42
jhawthorn and others added 4 commits July 11, 2017 17:11
Previously we selected the current store by pretty hacky means. We took
the value of either the SPREE_STORE HTTP header or the domain name, and
then selected a store either matching that code or had that value
contained anywhere in its url attribute. Failing to find these it falls
back to the default store.

Using SPREE_STORE and finding by code is intended to be used with a
reverse proxy like nginx, and is a good and powerful way to configure
Solidus' multi domain. But it does require extra and very specific
configuration, and isn't overly suitable as a default.

Selecting by url which contains the (header or domain name) value is
slow, surprising, and error-prone.

This commit removes support for the SPREE_STORE header, and allows only
one url per-store. Users needing this functionality can replicate it by
implementing their own store selector class.

This commit also allows the store selector to perform only a single
query to find the current store.
@jhawthorn jhawthorn force-pushed the select_store_single_query branch from 13fc5bf to 29aa494 Compare July 12, 2017 00:12
@jhawthorn jhawthorn merged commit f9f610b into solidusio:master Jul 12, 2017
brchristian added a commit to brchristian/solidus_virtual_gift_card that referenced this pull request Jun 11, 2019
brchristian added a commit to brchristian/solidus_virtual_gift_card that referenced this pull request Jun 11, 2019
brchristian added a commit to brchristian/solidus_virtual_gift_card that referenced this pull request Jun 12, 2019
brchristian added a commit to brchristian/solidus_virtual_gift_card that referenced this pull request Jun 30, 2019
DanielePalombo added a commit to nebulab/solidus that referenced this pull request Nov 13, 2020
kennyadsl pushed a commit to nebulab/solidus that referenced this pull request Nov 17, 2020
kennyadsl pushed a commit to nebulab/solidus that referenced this pull request Nov 19, 2020
kennyadsl pushed a commit to nebulab/solidus that referenced this pull request Nov 27, 2020
kennyadsl pushed a commit to nebulab/solidus that referenced this pull request Nov 27, 2020
kennyadsl pushed a commit to nebulab/solidus that referenced this pull request Dec 9, 2020
kennyadsl pushed a commit to nebulab/solidus that referenced this pull request Dec 10, 2020
DanielePalombo added a commit to nebulab/solidus that referenced this pull request Dec 11, 2020
kennyadsl pushed a commit to nebulab/solidus that referenced this pull request Dec 15, 2020
DanielePalombo added a commit to nebulab/solidus that referenced this pull request Dec 18, 2020
kennyadsl pushed a commit to nebulab/solidus that referenced this pull request Dec 21, 2020
kennyadsl pushed a commit to nebulab/solidus that referenced this pull request Jan 19, 2021
kennyadsl pushed a commit to nebulab/solidus that referenced this pull request Jan 28, 2021
kennyadsl pushed a commit to nebulab/solidus that referenced this pull request Jan 28, 2021
rmparr pushed a commit to rmparr/solidus that referenced this pull request Jun 1, 2022
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.

3 participants