[openstreetmap/openstreetmap-website] Lazy loading relation members (PR #6326)

mmd notifications at github.com
Mon Aug 18 08:30:55 UTC 2025


mmd-osm left a comment (openstreetmap/openstreetmap-website#6326)

Furthermore, prefetching member tags could be useful to avoid lots of small queries that are currently slowing down the process. The following could be called from the two new controllers:

```ruby
  def prefetch_member_tags(feature)
    members = feature.relation_members.map(&:member).compact
    grouped_members = members.group_by(&:class)

    {
      Node => :node_tags,
      Way => :way_tags,
      Relation => :relation_tags
    }.each do |klass, tag_assoc|
      records = grouped_members[klass] || []
      ActiveRecord::Associations::Preloader.new(
        :records => records,
        :associations => tag_assoc
      ).call
    end
  end
```



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

Message ID: <openstreetmap/openstreetmap-website/pull/6326/c3195663524 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20250818/322cf1cd/attachment.htm>


More information about the rails-dev mailing list