Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Core][Optimalization] Assign fallback locale for command based requests#13545

Merged
GSadee merged 5 commits into
Sylius:1.11from
SirDomin:refactor-locale-assigner
Jan 27, 2022
Merged

[Core][Optimalization] Assign fallback locale for command based requests#13545
GSadee merged 5 commits into
Sylius:1.11from
SirDomin:refactor-locale-assigner

Conversation

@SirDomin
Copy link
Copy Markdown
Contributor

@SirDomin SirDomin commented Jan 25, 2022

Q A
Branch? 1.11
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Related tickets
License MIT

After research we decided to assign fallback locale for messenger:consume command as it allows CatalogPromotions to be applied way faster than when checking locale for ~2000 product variants

There is also another way to check if we are running from command, with $_SERVER variable we can acccess:
image
but it gets abit tricky when using $_SERVER so decided to stay with this solution as the output can be the same

@SirDomin SirDomin requested a review from a team as a code owner January 25, 2022 23:10
@SirDomin SirDomin force-pushed the refactor-locale-assigner branch from 0b5af2b to 88c5a74 Compare January 25, 2022 23:12
@SirDomin SirDomin force-pushed the refactor-locale-assigner branch from 88c5a74 to 8883a6e Compare January 25, 2022 23:32
@vvasiloi
Copy link
Copy Markdown
Contributor

@SirDomin WDYT about an implementation similar to what I have described here: #9987 (comment)

@SirDomin
Copy link
Copy Markdown
Contributor Author

@vvasiloi it could work too, but im not sure about different contexts when using cli from behat/specs. This way make it generic in case when we add more ideas of this type.

Comment thread src/Sylius/Bundle/CoreBundle/Resources/config/services/checkers.xml Outdated
Comment thread src/Sylius/Component/Core/Checker/CommandBasedContextChecker.php Outdated
Comment thread src/Sylius/Component/Core/Translation/TranslatableEntityLocaleAssigner.php Outdated
{
$fallbackLocale = $this->translationLocaleProvider->getDefaultLocaleCode();

if ($this->commandBasedChecker !== null && $this->commandBasedChecker->isRunningFromCommand()) {
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.

Seeing this plus the extra constructor argument got me thinking, why not decorate this service instead of modifying it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I created 3rd not required argument along with deprecation note, i think both cases are good.

Comment thread src/Sylius/Component/Core/Translation/TranslatableEntityLocaleAssigner.php Outdated
Comment thread src/Sylius/Component/Core/Checker/CommandBasedContextChecker.php Outdated
Comment thread src/Sylius/Component/Core/Checker/CommandBasedContextChecker.php Outdated
Comment thread src/Sylius/Component/Core/Context/ProcessContextInterface.php Outdated
Comment thread src/Sylius/Component/Core/Translation/TranslatableEntityLocaleAssigner.php Outdated
@SirDomin SirDomin force-pushed the refactor-locale-assigner branch from e1194c0 to fd8ca81 Compare January 27, 2022 10:25
Copy link
Copy Markdown
Contributor

@lchrusciel lchrusciel left a comment

Choose a reason for hiding this comment

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

I can confirm, that this change makes significant improvement of CP process execution: https://blackfire.io/profiles/compare/39e14b49-45ec-4c52-91e9-9a8e7fbaedcd/graph

@GSadee GSadee merged commit 09f198c into Sylius:1.11 Jan 27, 2022
@GSadee
Copy link
Copy Markdown
Member

GSadee commented Jan 27, 2022

Thank you, @SirDomin! 🎉

GSadee added a commit that referenced this pull request Jan 28, 2022
…mand based requests (lchrusciel)

This PR was merged into the 1.11 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | 1.11
| Bug fix?        | no
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | 
| License         | MIT

I'm proposing alternative implementation to #13545, that takes into account request stack instead of env & SAPI. This way, we will have coherent behaviour among all envs which, in my opinion, will reduce possibility of bugs that exists on prod on dev, but where not detected by test.

Perhaps, we should consider similar behaviour just as a locale context - so fallbacking in the locale context to config value if CLI is executed

Commits
-------

db2630e [Core][Optimization] Request stack based implementation of CLIContextChecker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants