Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36750 - Add aggregated CV version content counts to count field and return via API #10746

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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