did searching

This commit is contained in:
Dylan Knutson
2025-09-07 17:47:53 +00:00
parent 3021bc4a97
commit 1905575d19
5 changed files with 39 additions and 15 deletions

View File

@@ -76,6 +76,24 @@ class Domain::UsersController < DomainController
authorize Domain::User
name = params[:name]&.downcase
name = ReduxApplicationRecord.sanitize_sql_like(name)
if name.starts_with?("did:plc:") || name.starts_with?("did:pkh:")
@user_search_names =
Domain::UserSearchName
.select(
"domain_user_search_names.*, domain_users.*, domain_users_bluesky_aux.did",
)
.select(
"levenshtein(domain_users_bluesky_aux.did, '#{name}') as distance",
)
.where(
user: Domain::User::BlueskyUser.where("did LIKE ?", "#{name}%"),
)
.joins(:user)
.limit(10)
return
end
@user_search_names =
Domain::UserSearchName
.select("domain_user_search_names.*, domain_users.*")

View File

@@ -8,14 +8,6 @@ class Domain::User::FaUser < Domain::User
due_timestamp :scanned_followed_by_at, 3.months
due_timestamp :scanned_incremental_at, 1.month
# todo - set this to be the right fav model type
has_many :user_post_favs,
-> { order(fa_fav_id: :desc) },
class_name: "Domain::UserPostFav::FaUserPostFav",
foreign_key: :user_id,
inverse_of: :user,
dependent: :destroy
belongs_to :last_user_page_log_entry,
foreign_key: :last_user_page_id,
class_name: "::HttpLogEntry",

View File

@@ -16,16 +16,14 @@ class Domain::UserPostFav < ReduxApplicationRecord
belongs_to :post, class_name: "Domain::Post", inverse_of: :user_post_favs
sig { params(user_klass: T.class_of(Domain::User), post_klass: T.class_of(Domain::Post)).void }
sig { params(user_klass: String, post_klass: String).void }
def self.user_post_fav_relationships(user_klass, post_klass)
belongs_to_with_counter_cache :user,
class_name: user_klass.name,
class_name: user_klass,
inverse_of: :user_post_favs,
counter_cache: :user_post_favs_count
belongs_to :post,
class_name: post_klass.name,
inverse_of: :user_post_favs
belongs_to :post, class_name: post_klass, inverse_of: :user_post_favs
end
scope :for_post_type,

View File

@@ -3,5 +3,13 @@
class Domain::UserPostFav::E621UserPostFav < Domain::UserPostFav
self.table_name = "domain_user_post_favs_e621"
user_post_fav_relationships Domain::User::E621User, Domain::Post::E621Post
# user_post_fav_relationships "Domain::User::E621User", "Domain::Post::E621Post"
belongs_to_with_counter_cache :user,
class_name: "Domain::User::E621User",
inverse_of: :user_post_favs,
counter_cache: :user_post_favs_count
belongs_to :post,
class_name: "Domain::Post::E621Post",
inverse_of: :user_post_favs
end

View File

@@ -1,7 +1,15 @@
# typed: strict
class Domain::UserPostFav::FaUserPostFav < Domain::UserPostFav
self.table_name = "domain_user_post_favs_fa"
user_post_fav_relationships Domain::User::FaUser, Domain::Post::FaPost
# user_post_fav_relationships "Domain::User::FaUser", "Domain::Post::FaPost"
belongs_to_with_counter_cache :user,
class_name: "Domain::User::FaUser",
inverse_of: :user_post_favs,
counter_cache: :user_post_favs_count
belongs_to :post,
class_name: "Domain::Post::FaPost",
inverse_of: :user_post_favs
scope :with_explicit_time_and_id,
-> { where.not(explicit_time: nil).where.not(fa_fav_id: nil) }