Skip to content

Commit

Permalink
Fix proposal map performance with hundreds of markers (decidim#13798)
Browse files Browse the repository at this point in the history
* Fix proposal map

* Remove unusued meeting script

* Fix test

* linters

* Revert "Remove unusued meeting script"

This reverts commit ea977f2.

* Manual revert
  • Loading branch information
alecslupu authored Jan 9, 2025
1 parent e506575 commit 257576a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ def index
else
@proposals = search.result

@all_geocoded_proposals = @proposals.geocoded if Decidim::Map.available?(:geocoding, :dynamic) && component_settings.geocoding_enabled?

@proposals = reorder(@proposals)
@proposals = paginate(@proposals)
@proposals = @proposals.includes(:component, :coauthorships, :attachments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module MapHelper
#
# geocoded_proposals - A collection of geocoded proposals
def proposals_data_for_map(geocoded_proposals)
geocoded_proposals.map do |proposal|
geocoded_proposals.select(&:geocoded_and_valid?).map do |proposal|
proposal_data_for_map(proposal)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<% if Decidim::Map.available?(:geocoding, :dynamic) && component_settings.geocoding_enabled? %>
<div class="proposal-list__map">
<%= dynamic_map_for proposals_data_for_map(@all_geocoded_proposals) do %>
<%= dynamic_map_for proposals_data_for_map(@proposals) do %>
<template id="marker-popup">
<div class="space-y-6">
<a href="${link}" class="card__list">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,15 @@ var $orderFilterInput = $('.order_filter');

$proposals.html('<%= j(render partial: "proposals").strip.html_safe %>');
$orderFilterInput.val('<%= order %>');

<% if Decidim::Map.available?(:geocoding, :dynamic) && component_settings.geocoding_enabled? %>
var $map = $("#map");
var controller = $map.data("map-controller");
if (controller) {
var markerData = JSON.parse('<%= escape_javascript proposals_data_for_map(@proposals).to_json.html_safe %>');
controller.clearMarkers();
if (markerData.length > 0 ) {
controller.addMarkers(markerData);
}
}
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ module Proposals

it "sets two different collections" do
geocoded_proposals = create_list(:proposal, 10, component:, latitude: 1.1, longitude: 2.2)
_non_geocoded_proposals = create_list(:proposal, 2, component:, latitude: nil, longitude: nil)
non_geocoded_proposals = create_list(:proposal, 2, component:, latitude: nil, longitude: nil)

get :index
expect(response).to have_http_status(:ok)
expect(subject).to render_template(:index)

expect(assigns(:proposals).count).to eq 12
expect(assigns(:all_geocoded_proposals)).to match_array(geocoded_proposals)
expect(assigns(:proposals)).to match_array(geocoded_proposals + non_geocoded_proposals)
end
end

Expand Down

0 comments on commit 257576a

Please sign in to comment.