[openstreetmap/openstreetmap-website] Move social link parsing to save-time (Issue #6904)

Andy Allan notifications at github.com
Wed Mar 18 16:14:40 UTC 2026


gravitystorm created an issue (openstreetmap/openstreetmap-website#6904)

Currently the SocialLink object has only one significant attribute: `url`.

However, when we display these URLs on the profile page, we do a certain amount of parsing - to determine the `platform` (for the icon) and the `name` to display (and a few other edge cases). This is done by matching each URL against [a list of regular expressions](https://github.com/openstreetmap/openstreetmap-website/blob/7943b4cf3d71742777af8487863a00ad70e41fd4/app/models/social_link.rb#L27-L67).

There's currently 39 regular expressions in the list, so if I have 10 social links on my profile, that's up to 390 regular expression matches to render the links on just that one page. Those 390 parses needs to be repeated every time the page is viewed. This is a lot of parsing and re-parsing of the same urls to get the same `platform` and `name` every time. 

An alternative is to extend the SocialLink model to have `platform` and `name` attributes, and do the parsing just once, at the time the model is saved. I don't intend for the UI to change, this is effectively just caching the results of the parsing.

The only disadvantage is that when the set of regular expressions changes (e.g. adding a new one), then existing SocialLinks aren't updated. This can either be left to individual users to re-save their links, or a "re-parse-all-social-links" rake task could be added and run whenever if was felt necessary. I think that would still be more lightweight than the current situation.

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

Message ID: <openstreetmap/openstreetmap-website/issues/6904 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20260318/6ca2b317/attachment.htm>


More information about the rails-dev mailing list