fix for routes

This commit is contained in:
Dylan Knutson
2025-03-13 16:48:49 +00:00
parent 32b9d606e7
commit aad67622fc
2 changed files with 47 additions and 31 deletions

View File

@@ -1,5 +1,7 @@
# typed: strict # typed: strict
class Domain::Fa::Job::UserPageJob < Domain::Fa::Job::Base class Domain::Fa::Job::UserPageJob < Domain::Fa::Job::Base
RECENT_USERS_THRESHOLD = T.let(12, Integer)
queue_as :fa_user_page queue_as :fa_user_page
queue_with_priority do queue_with_priority do
T.bind(self, Domain::Fa::Job::UserPageJob) T.bind(self, Domain::Fa::Job::UserPageJob)
@@ -167,7 +169,7 @@ class Domain::Fa::Job::UserPageJob < Domain::Fa::Job::Base
if recent_watching.empty? if recent_watching.empty?
logger.info(format_tags("skipping followed users scan, 0 watching")) logger.info(format_tags("skipping followed users scan, 0 watching"))
user.scanned_follows_at = Time.current user.scanned_follows_at = Time.current
elsif recent_watching.count < 12 elsif recent_watching.count < RECENT_USERS_THRESHOLD
logger.info( logger.info(
format_tags( format_tags(
"skipping followed users scan, #{recent_watching.count} watching < threshold", "skipping followed users scan, #{recent_watching.count} watching < threshold",
@@ -215,10 +217,16 @@ class Domain::Fa::Job::UserPageJob < Domain::Fa::Job::Base
end end
def check_skip_followed_by_users_scan(user, user_page) def check_skip_followed_by_users_scan(user, user_page)
recent_watchers = user_page.recent_watchers recent_watchers = user_page.recent_watchers
page_num_watched_by = user_page.num_watched_by
if recent_watchers.empty? if recent_watchers.empty?
logger.info(format_tags("skipping followed by scan, 0 watched")) logger.info(format_tags("skipping followed by scan, 0 watched"))
user.scanned_followed_by_at = Time.current user.scanned_followed_by_at = Time.current
elsif recent_watchers.count < 12 return
end
# by now, we know that there is at least one watcher
if recent_watchers.count < RECENT_USERS_THRESHOLD
logger.info( logger.info(
format_tags( format_tags(
"skipping followed by scan, #{recent_watchers.count} watchers < threshold", "skipping followed by scan, #{recent_watchers.count} watchers < threshold",
@@ -239,36 +247,34 @@ class Domain::Fa::Job::UserPageJob < Domain::Fa::Job::Base
unique_by: %i[from_id to_id], unique_by: %i[from_id to_id],
) )
user.scanned_followed_by_at = Time.current user.scanned_followed_by_at = Time.current
elsif recent_watchers.any? return
# if there are watchers, find the ones we've already recorded. if end
# all of them are known, then we can skip scanning favs the next time.
known_watchers =
Domain::User::FaUser.where(url_name: recent_watchers.map(&:url_name))
if known_watchers.count == recent_watchers.count
logger.info(
format_tags("skipping followed by scan, all watchers already known"),
)
user.scanned_followed_by_at = Time.current
end
elsif recent_watchers.any?
# if there are watchers, find the ones we've already recorded. if
# all of them are known, then we can assume watched users are up to date.
num_recent_watchers = recent_watchers.count
num_recent_watchers_known =
user
.followed_by_users
.where(url_name: recent_watchers.map(&:url_name))
.count
if (num_recent_watchers == num_recent_watchers_known) && # if there are watchers, find the ones we've already recorded. if
(user.followed_by_users.count == user_page.num_watched_by) # all of them are known, then we can skip scanning favs the next time.
logger.info( known_watchers =
format_tags( Domain::User::FaUser.where(url_name: recent_watchers.map(&:url_name))
"skipping UserFollowsJob, all watched users already known", if known_watchers.count == recent_watchers.count
), logger.info(
) format_tags("skipping followed by scan, all watchers already known"),
user.scanned_followed_by_at = Time.current )
user.scanned_followed_by_at = Time.current
return
end
# is the recent watcher in the last position known?
last_recent_watcher = T.must(recent_watchers.last)
last_recent_watcher_is_known =
known_watchers.any? do |user|
user.url_name == last_recent_watcher.url_name
end end
if last_recent_watcher_is_known
logger.info(
format_tags("skipping followed by scan, last watcher already known"),
)
user.scanned_followed_by_at = Time.current
return
end end
end end
end end

View File

@@ -1,4 +1,5 @@
# typed: strict # typed: strict
ID_CONSTRAINT = %r{([^/]+)}
Rails.application.routes.draw do Rails.application.routes.draw do
mount ActionCable.server => "/cable" mount ActionCable.server => "/cable"
@@ -24,6 +25,9 @@ Rails.application.routes.draw do
resources :users, resources :users,
as: :domain_users, as: :domain_users,
only: %i[show], only: %i[show],
constraints: {
id: ID_CONSTRAINT,
},
controller: "domain/users" do controller: "domain/users" do
get :search_by_name, on: :collection get :search_by_name, on: :collection
@@ -48,7 +52,13 @@ Rails.application.routes.draw do
as: :visual_results, as: :visual_results,
to: "domain/posts#visual_results" to: "domain/posts#visual_results"
end end
resources :users, only: %i[], controller: "domain/users", path: "" do resources :users,
only: %i[],
controller: "domain/users",
path: "",
constraints: {
id: ID_CONSTRAINT,
} do
get :faved_by, on: :collection, action: :users_faving_post get :faved_by, on: :collection, action: :users_faving_post
end end
end end