Merge branch '2201-i-hate-this' into 'develop'

User search: Once again, change uri handling.

Closes #2201

See merge request pleroma/pleroma!3048
This commit is contained in:
rinpatch 2020-09-30 13:37:46 +00:00
commit 2566467782
4 changed files with 18 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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, %{