Merge branch 'secfix/search-crash' into 'develop'
Fix crash done via search See merge request pleroma/secteam/pleroma!12
This commit is contained in:
parent
84acfab156
commit
74d46a1b09
|
@ -1125,31 +1125,31 @@ def get_followers_query(%User{} = user, nil) do
|
||||||
User.Query.build(%{followers: user, deactivated: false})
|
User.Query.build(%{followers: user, deactivated: false})
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_followers_query(user, page) do
|
def get_followers_query(%User{} = user, page) do
|
||||||
user
|
user
|
||||||
|> get_followers_query(nil)
|
|> get_followers_query(nil)
|
||||||
|> User.Query.paginate(page, 20)
|
|> User.Query.paginate(page, 20)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_followers_query(User.t()) :: Ecto.Query.t()
|
@spec get_followers_query(User.t()) :: Ecto.Query.t()
|
||||||
def get_followers_query(user), do: get_followers_query(user, nil)
|
def get_followers_query(%User{} = user), do: get_followers_query(user, nil)
|
||||||
|
|
||||||
@spec get_followers(User.t(), pos_integer() | nil) :: {:ok, list(User.t())}
|
@spec get_followers(User.t(), pos_integer() | nil) :: {:ok, list(User.t())}
|
||||||
def get_followers(user, page \\ nil) do
|
def get_followers(%User{} = user, page \\ nil) do
|
||||||
user
|
user
|
||||||
|> get_followers_query(page)
|
|> get_followers_query(page)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_external_followers(User.t(), pos_integer() | nil) :: {:ok, list(User.t())}
|
@spec get_external_followers(User.t(), pos_integer() | nil) :: {:ok, list(User.t())}
|
||||||
def get_external_followers(user, page \\ nil) do
|
def get_external_followers(%User{} = user, page \\ nil) do
|
||||||
user
|
user
|
||||||
|> get_followers_query(page)
|
|> get_followers_query(page)
|
||||||
|> User.Query.build(%{external: true})
|
|> User.Query.build(%{external: true})
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_followers_ids(user, page \\ nil) do
|
def get_followers_ids(%User{} = user, page \\ nil) do
|
||||||
user
|
user
|
||||||
|> get_followers_query(page)
|
|> get_followers_query(page)
|
||||||
|> select([u], u.id)
|
|> select([u], u.id)
|
||||||
|
@ -1161,29 +1161,29 @@ def get_friends_query(%User{} = user, nil) do
|
||||||
User.Query.build(%{friends: user, deactivated: false})
|
User.Query.build(%{friends: user, deactivated: false})
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_friends_query(user, page) do
|
def get_friends_query(%User{} = user, page) do
|
||||||
user
|
user
|
||||||
|> get_friends_query(nil)
|
|> get_friends_query(nil)
|
||||||
|> User.Query.paginate(page, 20)
|
|> User.Query.paginate(page, 20)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_friends_query(User.t()) :: Ecto.Query.t()
|
@spec get_friends_query(User.t()) :: Ecto.Query.t()
|
||||||
def get_friends_query(user), do: get_friends_query(user, nil)
|
def get_friends_query(%User{} = user), do: get_friends_query(user, nil)
|
||||||
|
|
||||||
def get_friends(user, page \\ nil) do
|
def get_friends(%User{} = user, page \\ nil) do
|
||||||
user
|
user
|
||||||
|> get_friends_query(page)
|
|> get_friends_query(page)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_friends_ap_ids(user) do
|
def get_friends_ap_ids(%User{} = user) do
|
||||||
user
|
user
|
||||||
|> get_friends_query(nil)
|
|> get_friends_query(nil)
|
||||||
|> select([u], u.ap_id)
|
|> select([u], u.ap_id)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_friends_ids(user, page \\ nil) do
|
def get_friends_ids(%User{} = user, page \\ nil) do
|
||||||
user
|
user
|
||||||
|> get_friends_query(page)
|
|> get_friends_query(page)
|
||||||
|> select([u], u.id)
|
|> select([u], u.id)
|
||||||
|
|
|
@ -115,8 +115,8 @@ defp trigram_rank(query, query_string) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp base_query(_user, false), do: User
|
defp base_query(%User{} = user, true), do: User.get_friends_query(user)
|
||||||
defp base_query(user, true), do: User.get_friends_query(user)
|
defp base_query(_user, _following), do: User
|
||||||
|
|
||||||
defp filter_invisible_users(query) do
|
defp filter_invisible_users(query) do
|
||||||
from(q in query, where: q.invisible == false)
|
from(q in query, where: q.invisible == false)
|
||||||
|
|
Loading…
Reference in New Issue