diff options
author | rinpatch <rinpatch@sdf.org> | 2020-09-30 13:37:46 +0000 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2020-09-30 13:37:46 +0000 |
commit | 2566467782e410aa910de9b55aece8c4ffd74ad1 (patch) | |
tree | effec95502007d8ad37165a9749938c9795d7073 | |
parent | 7f83b35a9dea7181b57d9b975742233813fa3a8b (diff) | |
parent | 1ae39441e6d516f8f1a0dd3ed47de9d8427477c5 (diff) | |
download | pleroma-2566467782e410aa910de9b55aece8c4ffd74ad1.tar.gz |
Merge branch '2201-i-hate-this' into 'develop'
User search: Once again, change uri handling.
Closes #2201
See merge request pleroma/pleroma!3048
-rw-r--r-- | lib/pleroma/user/search.ex | 5 | ||||
-rw-r--r-- | priv/repo/migrations/20200928145912_revert_citext_change.exs | 2 | ||||
-rw-r--r-- | priv/repo/migrations/20200930082320_user_ur_is_index_part_three.exs | 8 | ||||
-rw-r--r-- | test/user_search_test.exs | 6 |
4 files changed, 18 insertions, 3 deletions
diff --git a/lib/pleroma/user/search.ex b/lib/pleroma/user/search.ex index 03f2c552f..35a828008 100644 --- a/lib/pleroma/user/search.ex +++ b/lib/pleroma/user/search.ex @@ -54,8 +54,9 @@ defmodule Pleroma.User.Search do defp maybe_add_uri_match(list, query) do with {:ok, query} <- UriType.cast(query), - %User{} = user <- Pleroma.Repo.get_by(User, uri: query) do - [user.id | list] + q = from(u in User, where: u.uri == ^query, select: u.id), + users = Pleroma.Repo.all(q) do + users ++ list else _ -> list end diff --git a/priv/repo/migrations/20200928145912_revert_citext_change.exs b/priv/repo/migrations/20200928145912_revert_citext_change.exs index ab232f607..685a98533 100644 --- a/priv/repo/migrations/20200928145912_revert_citext_change.exs +++ b/priv/repo/migrations/20200928145912_revert_citext_change.exs @@ -6,6 +6,6 @@ defmodule Pleroma.Repo.Migrations.RevertCitextChange do modify(:uri, :text) end - create_if_not_exists(unique_index(:users, :uri)) + # create_if_not_exists(unique_index(:users, :uri)) end end diff --git a/priv/repo/migrations/20200930082320_user_ur_is_index_part_three.exs b/priv/repo/migrations/20200930082320_user_ur_is_index_part_three.exs new file mode 100644 index 000000000..816c6526e --- /dev/null +++ b/priv/repo/migrations/20200930082320_user_ur_is_index_part_three.exs @@ -0,0 +1,8 @@ +defmodule Pleroma.Repo.Migrations.UserURIsIndexPartThree do + use Ecto.Migration + + def change do + drop_if_exists(unique_index(:users, :uri)) + create_if_not_exists(index(:users, :uri)) + end +end diff --git a/test/user_search_test.exs b/test/user_search_test.exs index cc14e9741..c4b805005 100644 --- a/test/user_search_test.exs +++ b/test/user_search_test.exs @@ -36,6 +36,12 @@ defmodule Pleroma.UserSearchTest do assert first_user.id == user.id end + test "doesn't die if two users have the same uri" do + insert(:user, %{uri: "https://gensokyo.2hu/@raymoo"}) + insert(:user, %{uri: "https://gensokyo.2hu/@raymoo"}) + assert [_first_user, _second_user] = User.search("https://gensokyo.2hu/@raymoo") + end + test "returns a user with matching uri as the first result" do user = insert(:user, %{ |