X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fuser.ex;h=6a8129ac84b2572432d80e2cd77d76b27cbdcd6b;hb=46427cb90f31d72435b10134a85fad674e10f1cd;hp=c77fd6816af6a0cd1b4f04ecfaac7a4d518b4f9d;hpb=a80cdd590648d4eb812503fbf995598e6b4a95cb;p=akkoma diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index c77fd6816..6a8129ac8 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -21,6 +21,7 @@ defmodule Pleroma.User do field(:local, :boolean, default: true) field(:info, :map, default: %{}) field(:follower_address, :string) + field(:search_distance, :float, virtual: true) has_many(:notifications, Notification) timestamps() @@ -104,7 +105,7 @@ defmodule Pleroma.User do |> cast(params, [:bio, :name]) |> unique_constraint(:nickname) |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/) - |> validate_length(:bio, max: 1000) + |> validate_length(:bio, max: 5000) |> validate_length(:name, min: 1, max: 100) end @@ -322,6 +323,16 @@ defmodule Pleroma.User do update_and_set_cache(cs) end + def decrease_note_count(%User{} = user) do + note_count = user.info["note_count"] || 0 + note_count = if note_count <= 0, do: 0, else: note_count - 1 + new_info = Map.put(user.info, "note_count", note_count) + + cs = info_changeset(user, %{info: new_info}) + + update_and_set_cache(cs) + end + def update_note_count(%User{} = user) do note_count_query = from( @@ -389,16 +400,24 @@ defmodule Pleroma.User do User.get_or_fetch_by_nickname(query) end - q = + inner = from( u in User, - where: - fragment( - "(to_tsvector('english', ?) || to_tsvector('english', ?)) @@ plainto_tsquery('english', ?)", - u.nickname, - u.name, - ^query - ), + select_merge: %{ + search_distance: + fragment( + "? <-> (? || ?)", + ^query, + u.nickname, + u.name + ) + } + ) + + q = + from( + s in subquery(inner), + order_by: s.search_distance, limit: 20 )