[openstreetmap/openstreetmap-website] Cache preferred_languages (PR #6344)

mmd notifications at github.com
Fri Aug 22 20:15:56 UTC 2025


`preferred_languages.expand` in browse_helper.rb is a bit expensive, due to the Locale handling that's being triggered for every single element (see stacktrace below).

However, preferred_languages are not expected to change during a request. They seem like a good candidate for caching. preferred_languages is already cached in the application_controller, but the expanded version is not.

Caching should work on a request basis. After the request is done, the instance variable should be empty. Unit tests somehow don't have a concept of a request, that's why I had to manually set the value back to nil. 

In case an element doesn't have any tags, there isn't much point calling `feature_name`. Maybe this empty tags check could be moved from `printable_element_name` inside `feature_name`? 

I've seen about 50% performance improvement on top of #6338 by caching preferred_languages this way.

<img width="1573" height="663" alt="locale_keys" src="https://github.com/user-attachments/assets/795494ab-366b-4dc9-9b59-4a6e9988e72c" />

You can view, comment on, or merge this pull request online at:

  https://github.com/openstreetmap/openstreetmap-website/pull/6344

-- Commit Summary --

  * Cache preferred_languages

-- File Changes --

    M app/helpers/browse_helper.rb (8)
    M test/helpers/browse_helper_test.rb (3)

-- Patch Links --

https://github.com/openstreetmap/openstreetmap-website/pull/6344.patch
https://github.com/openstreetmap/openstreetmap-website/pull/6344.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6344
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/6344 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20250822/1ad1b751/attachment.htm>


More information about the rails-dev mailing list