[openstreetmap/openstreetmap-website] Cache social link platform and name at save time (PR #6950)

Matt Van Horn notifications at github.com
Tue Mar 31 07:43:39 UTC 2026


Social link URLs get parsed against 39 regexes on every profile page view. 10 links means 390 regex matches per load, every time. The platform and name never change unless the URL changes.

This adds `platform` and `name` columns to the `social_links` table and populates them via a `before_save` callback. The `parsed()` method returns cached values when present and falls back to the full regex scan for unmigrated records. View code is unchanged.

Changes:
- `app/models/social_link.rb`: split `parsed` into cached reader + private `parse_url`, added `before_save :cache_parsed_url`
- `db/migrate/..._add_platform_and_name_to_social_links.rb`: adds nullable `platform` and `name` columns

Existing records will continue working via the fallback path until they're re-saved. A rake task to backfill could be added separately if needed.

Fixes #6904

This contribution was developed with AI assistance (Codex).
You can view, comment on, or merge this pull request online at:

  https://github.com/openstreetmap/openstreetmap-website/pull/6950?email_source=notifications&email_token=AAK2OLPHITCKYH5V5F3UNZ34TNZKXA5CNFSNUABEM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UF4ZTINZQGU2DMMJSGOTHEZLBONXW5KTTOVRHGY3SNFRGKZFFMV3GK3TUVVYHEX3POBSW4X3DNRUWG2Y

-- Commit Summary --

  * Cache social link platform and name at save time

-- File Changes --

    M app/models/social_link.rb (26)
    A db/migrate/20260331004141_add_platform_and_name_to_social_links.rb (8)

-- Patch Links --

https://github.com/openstreetmap/openstreetmap-website/pull/6950.patch?email_source=notifications&email_token=AAK2OLP2ZYWPML6CDPOFTQL4TNZKXA5CNFSNUABEM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UF4ZTINZQGU2DMMJSGOTHEZLBONXW5KTTOVRHGY3SNFRGKZFFMV3GK3TUVZYHEX3QMF2GG2C7MNWGSY3Lhttps://github.com/openstreetmap/openstreetmap-website/pull/6950.diff?email_source=notifications&email_token=AAK2OLPHQMHW436T4LJDKLD4TNZKXA5CNFSNUABEM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UF4ZTINZQGU2DMMJSGOTHEZLBONXW5KTTOVRHGY3SNFRGKZFFMV3GK3TUVVYHEX3ENFTGMX3DNRUWG2Y
-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6950
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/6950 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20260331/2bb46959/attachment.htm>


More information about the rails-dev mailing list