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
Compare and Show latest version
2 files
+ 26
25
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -69,14 +69,19 @@ def update_last_used_storage_bytes!
update_column(:metadata, metadata.merge(last_used_storage_bytes: size))
end
def fetch_unassigned_projects(batch_size)
# Fetch all projects in the namespace that are not associated with any zoekt index
namespace.all_projects
.with_statistics
.left_joins(:zoekt_repositories) # Join with zoekt_repository, allowing NULL matches
.where(zoekt_repositories: { id: nil }) # Filter for projects without a zoekt repository
.joins(:statistics).order(repository_size: :desc) # Prioritize by repository size
.limit(batch_size) # Limit the results to the batch size
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
Loading