User search: Once again, change uri handling.
They can indeed be non-unique.
This commit is contained in:
parent
2a11068a11
commit
90fee49c52
|
@ -54,8 +54,9 @@ defp maybe_add_ap_id_match(list, query) do
|
||||||
|
|
||||||
defp maybe_add_uri_match(list, query) do
|
defp maybe_add_uri_match(list, query) do
|
||||||
with {:ok, query} <- UriType.cast(query),
|
with {:ok, query} <- UriType.cast(query),
|
||||||
%User{} = user <- Pleroma.Repo.get_by(User, uri: query) do
|
q = from(u in User, where: u.uri == ^query, select: u.id),
|
||||||
[user.id | list]
|
users = Pleroma.Repo.all(q) do
|
||||||
|
users ++ list
|
||||||
else
|
else
|
||||||
_ -> list
|
_ -> list
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
@ -36,6 +36,12 @@ test "returns a user with matching ap_id as the first result" do
|
||||||
assert first_user.id == user.id
|
assert first_user.id == user.id
|
||||||
end
|
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
|
test "returns a user with matching uri as the first result" do
|
||||||
user =
|
user =
|
||||||
insert(:user, %{
|
insert(:user, %{
|
||||||
|
|
Loading…
Reference in a new issue