Skip to content
Snippets Groups Projects

Add cron worker to automatically rollout zoekt exact code search to paid namespaces

Merged John Mason requested to merge jm-namespace-assignment-service into master
1 unresolved thread
Compare and Show latest version
6 files
+ 311
141
Compare changes
  • Side-by-side
  • Inline
Files
6
@@ -30,10 +30,6 @@ class EnabledNamespace < ApplicationRecord
raw_sql = 'min(zoekt_indices.state) = :state AND max(zoekt_indices.state) = :state'
joins(:indices).group(:id).having(raw_sql, state: Search::Zoekt::Index.states[:ready])
end
scope :pending_assignment, -> {
joins(:namespace).merge(Project.all_projects.with_statistics).distinct
.where("metadata->>'complete' IS NULL OR metadata->>'complete' = 'false'")
}
validates :metadata, json_schema: { filename: 'zoekt_enabled_namespaces_metadata' }
@@ -69,21 +65,6 @@ def update_last_used_storage_bytes!
update_column(:metadata, metadata.merge(last_used_storage_bytes: size))
end
def fetch_unassigned_projects(num_replicas:, last_project_id: nil)
scope = namespace.all_projects
.with_statistics
.left_joins(zoekt_repositories: { zoekt_index: :replica })
.joins(:statistics)
.group('projects.id, project_statistics.id, repository_size')
.order(repository_size: :desc) # Prioritize by repository size
# Filter projects with no repositories or fewer than required replicas
scope = scope.having('COUNT(DISTINCT zoekt_replicas.id) < ? OR COUNT(zoekt_repositories.id) = 0', num_replicas)
scope = scope.where('projects.id > ?', last_project_id) if last_project_id
scope
end
private
def only_root_namespaces_can_be_indexed
Loading