From 5055bd4adcf84cc0fc30f483437a0a1924e64d68 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 3 Oct 2022 19:45:29 +0200 Subject: [PATCH] Consider the events from the same organizer actor or group in first Signed-off-by: Thomas Citharel --- lib/mobilizon/events/events.ex | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 9ad6d0550..cfc3804e0 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -1693,11 +1693,14 @@ defmodule Mobilizon.Events do id: event_id, tags: tags, physical_address: physical_address, + organizer_actor: %Actor{id: organizer_actor_id}, + attributed_to: attributed_to, category: category, language: language }) do event_tags_ids = Enum.map(tags, & &1.id) geom = if is_nil(physical_address), do: nil, else: physical_address.geom + group_id = if is_nil(attributed_to), do: nil, else: attributed_to.id Event |> distinct([e], e.id) @@ -1710,13 +1713,18 @@ defmodule Mobilizon.Events do |> where( [e, et, a], fragment( - "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (?::geography is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 > ?", + "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (? = ?)::int * 2 + (?::int is null or ? = ?)::int * 2 + (?::geography is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 > ?", e.language, ^language, et.tag_id, ^event_tags_ids, e.category, ^category, + e.organizer_actor_id, + ^organizer_actor_id, + ^group_id, + e.attributed_to_id, + ^group_id, ^geom, ^geom, a.geom, @@ -1728,13 +1736,18 @@ defmodule Mobilizon.Events do |> order_by( [e, et, a], fragment( - "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (?::geography is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 DESC", + "(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (? = ?)::int * 2 + (?::int is null or ? = ?)::int * 2 + (?::geography is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 DESC", e.language, ^language, et.tag_id, ^event_tags_ids, e.category, ^category, + e.organizer_actor_id, + ^organizer_actor_id, + ^group_id, + e.attributed_to_id, + ^group_id, ^geom, ^geom, a.geom,