Rename the finder methods to make clear its real intent

parent 5da58325
...@@ -29,9 +29,9 @@ module Geo ...@@ -29,9 +29,9 @@ module Geo
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def find_outdated_projects(batch_size:) def find_recently_updated_projects(batch_size:)
query = build_query_to_find_outdated_projects(batch_size: batch_size) query = build_query_to_find_recently_updated_projects(batch_size: batch_size)
cte = Gitlab::SQL::CTE.new(:outdated_projects, query) cte = Gitlab::SQL::CTE.new(:recently_updated_projects, query)
Project.with(cte.to_arel) Project.with(cte.to_arel)
.from(cte.alias_to(projects_table)) .from(cte.alias_to(projects_table))
...@@ -40,12 +40,12 @@ module Geo ...@@ -40,12 +40,12 @@ module Geo
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def find_unverified_projects(batch_size:) def find_never_verified_projects(batch_size:)
relation = relation =
Project.select(:id) Project.select(:id)
.with_route .with_route
.joins(left_join_repository_state) .joins(left_join_repository_state)
.where(repository_never_verified) .where(repository_state_table[:project_id].eq(nil))
.limit(batch_size) .limit(batch_size)
apply_shard_restriction(relation) apply_shard_restriction(relation)
...@@ -96,12 +96,20 @@ module Geo ...@@ -96,12 +96,20 @@ module Geo
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def build_query_to_find_outdated_projects(batch_size:) def build_query_to_find_recently_updated_projects(batch_size:)
repository_recently_updated =
repository_state_table[:repository_verification_checksum].eq(nil)
.and(repository_state_table[:last_repository_verification_failure].eq(nil))
wiki_recently_updated =
repository_state_table[:wiki_verification_checksum].eq(nil)
.and(repository_state_table[:last_wiki_verification_failure].eq(nil))
query = query =
projects_table projects_table
.join(repository_state_table).on(project_id_matcher) .join(repository_state_table).on(project_id_matcher)
.project(projects_table[:id], projects_table[:last_repository_updated_at]) .project(projects_table[:id], projects_table[:last_repository_updated_at])
.where(repository_outdated.or(wiki_outdated)) .where(repository_recently_updated.or(wiki_recently_updated))
.take(batch_size) .take(batch_size)
apply_shard_restriction(query) apply_shard_restriction(query)
...@@ -149,20 +157,6 @@ module Geo ...@@ -149,20 +157,6 @@ module Geo
.join_sources .join_sources
end end
def repository_outdated
repository_state_table[:repository_verification_checksum].eq(nil)
.and(repository_state_table[:last_repository_verification_failure].eq(nil))
end
def wiki_outdated
repository_state_table[:wiki_verification_checksum].eq(nil)
.and(repository_state_table[:last_wiki_verification_failure].eq(nil))
end
def repository_never_verified
repository_state_table[:project_id].eq(nil)
end
def last_repository_updated_at_asc def last_repository_updated_at_asc
Gitlab::Database.nulls_last_order('projects.last_repository_updated_at', 'ASC') Gitlab::Database.nulls_last_order('projects.last_repository_updated_at', 'ASC')
end end
......
...@@ -44,11 +44,11 @@ module Geo ...@@ -44,11 +44,11 @@ module Geo
end end
def load_pending_resources def load_pending_resources
resources = find_unverified_project_ids(batch_size: db_retrieve_batch_size) resources = find_never_verified_project_ids(batch_size: db_retrieve_batch_size)
remaining_capacity = db_retrieve_batch_size - resources.size remaining_capacity = db_retrieve_batch_size - resources.size
return resources if remaining_capacity.zero? return resources if remaining_capacity.zero?
resources += find_outdated_project_ids(batch_size: remaining_capacity) resources += find_recently_updated_project_ids(batch_size: remaining_capacity)
remaining_capacity = db_retrieve_batch_size - resources.size remaining_capacity = db_retrieve_batch_size - resources.size
return resources if remaining_capacity.zero? return resources if remaining_capacity.zero?
...@@ -56,14 +56,14 @@ module Geo ...@@ -56,14 +56,14 @@ module Geo
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def find_unverified_project_ids(batch_size:) def find_never_verified_project_ids(batch_size:)
finder.find_unverified_projects(batch_size: batch_size).pluck(:id) finder.find_never_verified_projects(batch_size: batch_size).pluck(:id)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def find_outdated_project_ids(batch_size:) def find_recently_updated_project_ids(batch_size:)
finder.find_outdated_projects(batch_size: batch_size).pluck(:id) finder.find_recently_updated_projects(batch_size: batch_size).pluck(:id)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment