From b284ecd17927a25dc41cbc37eeb46cef170d00db Mon Sep 17 00:00:00 2001 From: Jerry Feng Date: Mon, 10 Feb 2025 10:22:31 -0500 Subject: [PATCH 1/3] Bundle Analysis: add a getter for cache config --- graphql_api/tests/test_commit.py | 5 +++++ graphql_api/types/bundle_analysis/base.graphql | 1 + graphql_api/types/bundle_analysis/base.py | 7 +++++++ requirements.in | 2 +- requirements.txt | 2 +- services/bundle_analysis.py | 10 ++++++++++ 6 files changed, 25 insertions(+), 2 deletions(-) diff --git a/graphql_api/tests/test_commit.py b/graphql_api/tests/test_commit.py index c41177a627..1d401e2fe4 100644 --- a/graphql_api/tests/test_commit.py +++ b/graphql_api/tests/test_commit.py @@ -1202,6 +1202,7 @@ def test_bundle_analysis_report(self, get_storage_service): } } isCached + cacheConfig } bundleData { loadTime { @@ -1263,6 +1264,7 @@ def test_bundle_analysis_report(self, get_storage_service): }, }, "isCached": False, + "cacheConfig": False, }, { "name": "b2", @@ -1285,6 +1287,7 @@ def test_bundle_analysis_report(self, get_storage_service): }, }, "isCached": False, + "cacheConfig": False, }, { "name": "b3", @@ -1307,6 +1310,7 @@ def test_bundle_analysis_report(self, get_storage_service): }, }, "isCached": False, + "cacheConfig": False, }, { "name": "b5", @@ -1329,6 +1333,7 @@ def test_bundle_analysis_report(self, get_storage_service): }, }, "isCached": False, + "cacheConfig": False, }, ], "bundleData": { diff --git a/graphql_api/types/bundle_analysis/base.graphql b/graphql_api/types/bundle_analysis/base.graphql index 6bbe8f40af..d6102ca91b 100644 --- a/graphql_api/types/bundle_analysis/base.graphql +++ b/graphql_api/types/bundle_analysis/base.graphql @@ -93,6 +93,7 @@ type BundleReport { before: String ): AssetConnection info: BundleReportInfo! + cacheConfig: Boolean! } type BundleAnalysisMeasurements{ diff --git a/graphql_api/types/bundle_analysis/base.py b/graphql_api/types/bundle_analysis/base.py index dce5f1435e..1620fde3ac 100644 --- a/graphql_api/types/bundle_analysis/base.py +++ b/graphql_api/types/bundle_analysis/base.py @@ -372,6 +372,13 @@ def resolve_bundle_report_is_cached( return bundle_report.is_cached +@bundle_report_bindable.field("cacheConfig") +def resolve_bundle_report_cache_config( + bundle_report: BundleReport, info: GraphQLResolveInfo +) -> bool: + return bundle_report.cache_config(info.context["commit"].repository.pk) + + @bundle_report_bindable.field("info") def resolve_bundle_report_info( bundle_report: BundleReport, info: GraphQLResolveInfo diff --git a/requirements.in b/requirements.in index cbb170b2f6..c6315972aa 100644 --- a/requirements.in +++ b/requirements.in @@ -25,7 +25,7 @@ freezegun google-cloud-pubsub gunicorn>=22.0.0 https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz#egg=codecovopentelem -https://github.com/codecov/shared/archive/abf6180de5cee3ac99b7fbf909bd82c7325063fd.tar.gz#egg=shared +https://github.com/codecov/shared/archive/27b1298754fe5cd0bf458d6a17b5f8c8ab87d377.tar.gz#egg=shared https://github.com/photocrowd/django-cursor-pagination/archive/f560902696b0c8509e4d95c10ba0d62700181d84.tar.gz idna>=3.7 minio diff --git a/requirements.txt b/requirements.txt index 0d2dc25a9e..858ba74d8f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -416,7 +416,7 @@ sentry-sdk[celery]==2.13.0 # shared setproctitle==1.1.10 # via -r requirements.in -shared @ https://github.com/codecov/shared/archive/abf6180de5cee3ac99b7fbf909bd82c7325063fd.tar.gz +shared @ https://github.com/codecov/shared/archive/27b1298754fe5cd0bf458d6a17b5f8c8ab87d377.tar.gz # via -r requirements.in simplejson==3.17.2 # via -r requirements.in diff --git a/services/bundle_analysis.py b/services/bundle_analysis.py index e949e66026..570cbbda18 100644 --- a/services/bundle_analysis.py +++ b/services/bundle_analysis.py @@ -18,8 +18,12 @@ from shared.bundle_analysis import BundleReport as SharedBundleReport from shared.bundle_analysis import ModuleReport as SharedModuleReport from shared.bundle_analysis.models import AssetType +from shared.django_apps.bundle_analysis.service.bundle_analysis import ( + BundleAnalysisCacheConfigService, +) from shared.storage import get_appropriate_storage_service +from codecov.db import sync_to_async from core.models import Commit, Repository from graphql_api.actions.measurements import ( measurements_by_ids, @@ -306,6 +310,12 @@ def is_cached(self) -> bool: def info(self) -> dict: return self.report.info() + @sync_to_async + def cache_config(self, repo_id: int) -> bool: + return BundleAnalysisCacheConfigService.get_cache_option( + repo_id=repo_id, name=self.report.name + ) + @dataclass class BundleReportInfo(object): From 9f148afd9ef6fead4b95860ddfe42dd35d017258 Mon Sep 17 00:00:00 2001 From: Jerry Feng Date: Mon, 10 Feb 2025 11:17:50 -0500 Subject: [PATCH 2/3] update mutation to return cacheConfig --- .../interactors/tests/test_update_bundle_cache_config.py | 4 ++-- .../repository/interactors/update_bundle_cache_config.py | 1 + graphql_api/tests/mutation/test_update_bundle_cache_config.py | 1 + .../update_bundle_cache_config.graphql | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/commands/repository/interactors/tests/test_update_bundle_cache_config.py b/core/commands/repository/interactors/tests/test_update_bundle_cache_config.py index 986a99bcf6..19270f10cd 100644 --- a/core/commands/repository/interactors/tests/test_update_bundle_cache_config.py +++ b/core/commands/repository/interactors/tests/test_update_bundle_cache_config.py @@ -76,8 +76,8 @@ def test_update_bundles_successfully(self): ) assert res == [ - {"bundle_name": "bundle1", "is_cached": False}, - {"bundle_name": "bundle2", "is_cached": True}, + {"bundle_name": "bundle1", "is_cached": False, "cache_config": False}, + {"bundle_name": "bundle2", "is_cached": True, "cache_config": True}, ] assert len(CacheConfig.objects.all()) == 2 diff --git a/core/commands/repository/interactors/update_bundle_cache_config.py b/core/commands/repository/interactors/update_bundle_cache_config.py index afdea2e402..544a9b6509 100644 --- a/core/commands/repository/interactors/update_bundle_cache_config.py +++ b/core/commands/repository/interactors/update_bundle_cache_config.py @@ -57,6 +57,7 @@ def execute( { "bundle_name": bundle_name, "is_cached": is_caching, + "cache_config": is_caching, } ) return results diff --git a/graphql_api/tests/mutation/test_update_bundle_cache_config.py b/graphql_api/tests/mutation/test_update_bundle_cache_config.py index 55f8a210ff..10b8b68c22 100644 --- a/graphql_api/tests/mutation/test_update_bundle_cache_config.py +++ b/graphql_api/tests/mutation/test_update_bundle_cache_config.py @@ -30,6 +30,7 @@ results { bundleName isCached + cacheConfig } error { __typename diff --git a/graphql_api/types/mutation/update_bundle_cache_config/update_bundle_cache_config.graphql b/graphql_api/types/mutation/update_bundle_cache_config/update_bundle_cache_config.graphql index 34e7e02fde..e07c60530a 100644 --- a/graphql_api/types/mutation/update_bundle_cache_config/update_bundle_cache_config.graphql +++ b/graphql_api/types/mutation/update_bundle_cache_config/update_bundle_cache_config.graphql @@ -3,6 +3,7 @@ union UpdateBundleCacheConfigError = UnauthenticatedError | ValidationError type UpdateBundleCacheConfigResult { bundleName: String isCached: Boolean + cacheConfig: Boolean } type UpdateBundleCacheConfigPayload { From 9d119aed63cb935124726c7c6fdedc2fb29c7f4f Mon Sep 17 00:00:00 2001 From: Jerry Feng Date: Mon, 10 Feb 2025 15:40:38 -0500 Subject: [PATCH 3/3] update shared --- requirements.in | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.in b/requirements.in index 2e5f197d53..9b5840ede7 100644 --- a/requirements.in +++ b/requirements.in @@ -25,7 +25,7 @@ freezegun google-cloud-pubsub gunicorn>=22.0.0 https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz#egg=codecovopentelem -https://github.com/codecov/shared/archive/986a0971a633eac2a3005947102cb5f4d9119989.tar.gz#egg=shared +https://github.com/codecov/shared/archive/69b736859ab71e1e3e91018439a6cb6b792502f3.tar.gz#egg=shared https://github.com/photocrowd/django-cursor-pagination/archive/f560902696b0c8509e4d95c10ba0d62700181d84.tar.gz idna>=3.7 minio diff --git a/requirements.txt b/requirements.txt index ea9a543817..640458554c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -416,7 +416,7 @@ sentry-sdk[celery]==2.13.0 # shared setproctitle==1.1.10 # via -r requirements.in -shared @ https://github.com/codecov/shared/archive/986a0971a633eac2a3005947102cb5f4d9119989.tar.gz +shared @ https://github.com/codecov/shared/archive/69b736859ab71e1e3e91018439a6cb6b792502f3.tar.gz # via -r requirements.in simplejson==3.17.2 # via -r requirements.in