Skip to content

Commit

Permalink
Fixes #36750 - Add aggregated CV version content counts to count fiel…
Browse files Browse the repository at this point in the history
…d and return via API (#10746)

(cherry picked from commit dbde8b4)
  • Loading branch information
sjha4 authored Sep 20, 2023
1 parent 506c528 commit 244a606
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
15 changes: 14 additions & 1 deletion app/models/katello/concerns/smart_proxy_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,25 @@ def update_content_counts!
translated_counts[::Katello::Pulp3::PulpContentUnit.katello_name_from_pulpcore_name(name, repo)] = count
end
end
new_content_counts[:content_view_versions][repo.content_view_version_id] ||= { repositories: {} }
new_content_counts[:content_view_versions][repo.content_view_version_id] ||= { repositories: {}, cv_version_content_counts: {}}
new_content_counts[:content_view_versions][repo.content_view_version_id][:repositories][repo.id] = translated_counts
new_content_counts = aggregated_cv_version_count!(repo.content_view_version_id, new_content_counts, translated_counts)
end
update(content_counts: new_content_counts)
end

def aggregated_cv_version_count!(cv_version_id, cvv_content_counts, repo_counts)
repo_counts.keys.each do |content_type|
cvv_content_counts[:content_view_versions][cv_version_id][:cv_version_content_counts][content_type] =
if cvv_content_counts[:content_view_versions][cv_version_id][:cv_version_content_counts][content_type]
cvv_content_counts[:content_view_versions][cv_version_id][:cv_version_content_counts][content_type] + repo_counts[content_type]
else
repo_counts[content_type]
end
end
cvv_content_counts
end

def sync_container_gateway
if has_feature?(::SmartProxy::CONTAINER_GATEWAY_FEATURE)
update_container_repo_list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ child @lifecycle_environments => :lifecycle_environments do
:up_to_date => @capsule.repos_pending_sync(env, content_view).empty?,
:counts => {
:repositories => ::Katello::ContentViewVersion.in_environment(env).find_by(:content_view => content_view)&.archived_repos&.count
}
},
:content_counts => @capsule.content_counts
}
attributes
end
Expand Down
18 changes: 18 additions & 0 deletions test/models/concerns/smart_proxy_extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ def test_update_content_counts
ostree_repo.id.to_s => {"ostree_ref" => 30 },
deb_repo.id.to_s => { "deb" => 987 },
python_repo.id.to_s => { "python_package" => 42 }
},
"cv_version_content_counts" =>
{ "erratum" => 4,
"srpm" => 1,
"rpm" => 31,
"rpm.modulemd" => 7,
"rpm.modulemd_defaults" => 3,
"package_group" => 7,
"rpm.packagecategory" => 1,
"file" => 100,
"ansible_collection" => 802,
"container.blob" => 30,
"docker_manifest_list" => 1,
"docker_manifest" => 9,
"docker_tag" => 5,
"ostree_ref" => 30,
"deb" => 987,
"python_package" => 42
}
}
}
Expand Down

0 comments on commit 244a606

Please sign in to comment.