Consider the events from the same organizer actor or group in first

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-10-03 19:45:29 +02:00
parent 1601153062
commit 5055bd4adc
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -1693,11 +1693,14 @@ defmodule Mobilizon.Events do
id: event_id, id: event_id,
tags: tags, tags: tags,
physical_address: physical_address, physical_address: physical_address,
organizer_actor: %Actor{id: organizer_actor_id},
attributed_to: attributed_to,
category: category, category: category,
language: language language: language
}) do }) do
event_tags_ids = Enum.map(tags, & &1.id) event_tags_ids = Enum.map(tags, & &1.id)
geom = if is_nil(physical_address), do: nil, else: physical_address.geom 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 Event
|> distinct([e], e.id) |> distinct([e], e.id)
@ -1710,13 +1713,18 @@ defmodule Mobilizon.Events do
|> where( |> where(
[e, et, a], [e, et, a],
fragment( 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, e.language,
^language, ^language,
et.tag_id, et.tag_id,
^event_tags_ids, ^event_tags_ids,
e.category, e.category,
^category, ^category,
e.organizer_actor_id,
^organizer_actor_id,
^group_id,
e.attributed_to_id,
^group_id,
^geom, ^geom,
^geom, ^geom,
a.geom, a.geom,
@ -1728,13 +1736,18 @@ defmodule Mobilizon.Events do
|> order_by( |> order_by(
[e, et, a], [e, et, a],
fragment( 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, e.language,
^language, ^language,
et.tag_id, et.tag_id,
^event_tags_ids, ^event_tags_ids,
e.category, e.category,
^category, ^category,
e.organizer_actor_id,
^organizer_actor_id,
^group_id,
e.attributed_to_id,
^group_id,
^geom, ^geom,
^geom, ^geom,
a.geom, a.geom,