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

PERF: Ensure locales are always handled as symbols internally #12897

Merged
merged 1 commit into from Apr 30, 2021

Conversation

davidtaylorhq
Copy link
Member

Sometimes, parts of the application pass in the locale as a string, not a symbol. This was causing the translate_accelerator to cache two versions of the locale separately: one cache for the symbol version, and one cache for the string version. For example, in a running production process:

irb(main):001:0> I18n.instance_variable_get(:@loaded_locales)
=> [:en, "en"]

This commit ensures the locale key is always converted to a symbol, and adds a spec to ensure the same locale cannot appear twice in @loaded_locales

Sometimes, parts of the application pass in the locale as a string, not a symbol. This was causing the translate_accelerator to cache two versions of the locale separately: one cache for the symbol version, and one cache for the string version. For example, in a running production process:

```
irb(main):001:0> I18n.instance_variable_get(:@loaded_locales)
=> [:en, "en"]
```

This commit ensures the `locale` key is always converted to a symbol, and adds a spec to ensure the same locale cannot appear twice in `@loaded_locales`
Copy link
Contributor

@eviltrout eviltrout left a comment

Choose a reason for hiding this comment

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

Nice catch.

@davidtaylorhq davidtaylorhq merged commit 1bc1a43 into master Apr 30, 2021
@davidtaylorhq davidtaylorhq deleted the locale-symbols branch April 30, 2021 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants