From 26f280a3d263a2b6efb948118803e2062760429a Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Fri, 5 Mar 2021 13:11:30 -0500 Subject: [PATCH] always include user's current filter in recent filter list fixes derpibooru/philomena#223 fixes furbooru/philomena#29 fixes furbooru/philomena#53 --- lib/philomena/filters.ex | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/philomena/filters.ex b/lib/philomena/filters.ex index 8011e008..363926f9 100644 --- a/lib/philomena/filters.ex +++ b/lib/philomena/filters.ex @@ -141,6 +141,10 @@ defmodule Philomena.Filters do end def recent_and_user_filters(user) do + recent_filter_ids = + [user.current_filter_id | user.recent_filter_ids] + |> Enum.take(10) + user_filters = Filter |> select([f], %{id: f.id, name: f.name, recent: ^"f"}) @@ -150,10 +154,9 @@ defmodule Philomena.Filters do recent_filters = Filter |> select([f], %{id: f.id, name: f.name, recent: ^"t"}) - |> where([f], f.id in ^user.recent_filter_ids) - |> limit(10) + |> where([f], f.id in ^recent_filter_ids) - union(recent_filters, ^user_filters) + union_all(recent_filters, ^user_filters) |> Repo.all() |> Enum.sort_by(fn f -> Enum.find_index(user.recent_filter_ids, fn id -> f.id == id end)