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

Idea pitch: Generate only unique routes and use I18n.fallbacks to generate as little routes as needed #273

Open
xtr3me opened this issue Nov 16, 2022 · 1 comment

Comments

@xtr3me
Copy link

xtr3me commented Nov 16, 2022

Within our company we are using the route_translator gem for a long time already but we noticed that within our setup we generate over 11k routes and most of them are not unique. This has a profound impact on the memory usage of our app.

By diving into this we noticed that we have a lot of duplicate routes due to our setup. Currently we are using brand specific locales and falling back on generic locales when needed. But in many cases these translations are actually duplicated.

The following locales will cause 2 routes being generated with the same path. (made up example to reflect the issue)

nl_stw:
  people: mensen

nl:
  people: mensen
resources :people

Output:

GET       /mensen(.:format)                      people#index {:locale=>"nl_stw"}
GET       /mensen(.:format)                      people#index {:locale=>"nl"}
etc..

To combat this I dug into route_translator and started tinkering with it's internals to find a way to not generate duplicate routes and using the fallbacks to still use the correct route translation.

Within the following PR (to my own fork) i've made an example implementation and i'm wondering if this would be something that this project is interested in or that it falls outside of the scope of this project.
https://github.com/xtr3me/route_translator/pull/2/files

This PR reduces the amount of routes for us from 11k to around 2200 and it drops the memory usage by almost 100mb.

The downside is that we cannot use the locale param, but from our testing this never worked for us as Rails will select the first matching route it finds.

The PR itself still needs tests to be added and a general cleanup of the code. But I will only go forward with that if it has any chance it will be incorporated upstream.

TLDR; Is this something route_translator wants to embed or does it fall out of scope?

@tagliala
Copy link
Collaborator

Hi,

apologies for the late reply.

Can I have more information on how this works?

Is it using host_locales or force_locale features to detect the proper locale?

Can you make the minimal changes to reproduce at https://github.com/diowa/ruby3-rails7-bootstrap-heroku/tree/route_translator ?

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

No branches or pull requests

2 participants