Refactor Namespace#all_projects

The following discussion from !43322 (merged) should be addressed:

@cwiesner @shreyasagarwal

  • We made the following test on gprd rails console, for the largest namespace and found 4 seconds for the most pessimistic case.
  • We may go on with the current MR and open a followup MR for Namespace#all_projects to use recursive approach rather than routes-based one.
aa_top_level_namespace = 'gbobject'

aa_sql = %Q|SELECT SUM(("project_statistics"."repository_size" - "projects"."repository_size_limit")) FROM "projects" INNER JOIN routes rs ON rs.source_id = projects.id AND rs.source_type = 'Project' INNER JOIN "project_statistics" ON "project_statistics"."project_id" = "projects"."id" WHERE (rs.path LIKE '#{aa_top_level_namespace}/%') AND (projects.repository_size_limit != 0 AND project_statistics.repository_size > projects.repository_size_limit)|

[Time.now, ActiveRecord::Base.connection.execute(aa_sql).to_json, Time.now]
Edited by Corinna Gogolok