Skip to content

Commit

Permalink
Remove obsolete cleanup from BundleAnalysis (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Aug 6, 2024
1 parent 24c8d91 commit 40e1262
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
8 changes: 4 additions & 4 deletions graphql_api/actions/measurements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Iterable, Mapping, Optional
from typing import Any, Dict, Iterable, List, Optional

from django.db.models import Max, QuerySet

Expand All @@ -16,7 +16,7 @@ def measurements_by_ids(
before: datetime,
after: Optional[datetime] = None,
branch: Optional[str] = None,
) -> Mapping[int, Iterable[dict]]:
) -> Dict[int, List[Dict[str, Any]]]:
queryset = MeasurementSummary.agg_by(interval).filter(
name=measurable_name,
owner_id=repository.author_id,
Expand All @@ -38,7 +38,7 @@ def measurements_by_ids(
)

# group by measurable_id
measurements: Mapping[int, Iterable[dict]] = {}
measurements: Dict[int, List[Dict[str, Any]]] = {}
for measurement in queryset:
measurable_id = measurement["measurable_id"]
if measurable_id not in measurements:
Expand All @@ -51,7 +51,7 @@ def measurements_by_ids(
def measurements_last_uploaded_before_start_date(
repo_id: int,
measurable_name: str,
measurable_ids: Iterable[str],
measurable_ids: List[int],
start_date: datetime,
branch: Optional[str] = None,
) -> QuerySet:
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ factory-boy
fakeredis
freezegun
https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz#egg=codecovopentelem
https://github.com/codecov/shared/archive/14d8093f85adf1b99df763354c10ec0eaf86ee43.tar.gz#egg=shared
https://github.com/codecov/shared/archive/58c6f4f0a0fa1a5d931466e0a63f5f15349546d5.tar.gz#egg=shared
google-cloud-pubsub
gunicorn>=22.0.0
https://github.com/photocrowd/django-cursor-pagination/archive/f560902696b0c8509e4d95c10ba0d62700181d84.tar.gz
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ googleapis-common-protos[grpc]==1.59.1
# grpcio-status
graphql-core==3.2.3
# via ariadne
greenlet==3.0.3
# via sqlalchemy
grpc-google-iam-v1==0.12.6
# via google-cloud-pubsub
grpcio==1.62.1
Expand Down Expand Up @@ -417,7 +419,7 @@ sentry-sdk[celery]==1.44.1
# shared
setproctitle==1.1.10
# via -r requirements.in
shared @ https://github.com/codecov/shared/archive/14d8093f85adf1b99df763354c10ec0eaf86ee43.tar.gz
shared @ https://github.com/codecov/shared/archive/58c6f4f0a0fa1a5d931466e0a63f5f15349546d5.tar.gz
# via -r requirements.in
simplejson==3.17.2
# via -r requirements.in
Expand Down
18 changes: 3 additions & 15 deletions services/bundle_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import dataclass
from datetime import datetime
from decimal import Decimal
from typing import Any, Dict, Iterable, List, Optional
from typing import Any, Dict, Iterable, List, Mapping, Optional

from django.utils.functional import cached_property
from shared.bundle_analysis import AssetReport as SharedAssetReport
Expand Down Expand Up @@ -84,7 +84,7 @@ def __init__(
asset_type: BundleAnalysisMeasurementsAssetType,
asset_name: Optional[str],
interval: Interval,
after: datetime,
after: Optional[datetime],
before: datetime,
):
self.raw_measurements = raw_measurements
Expand Down Expand Up @@ -283,11 +283,6 @@ def is_cached(self) -> bool:
class BundleAnalysisReport(object):
def __init__(self, report: SharedBundleAnalysisReport):
self.report = report
self.cleanup()

def cleanup(self) -> None:
if self.report and self.report.db_session:
self.report.db_session.close()

def bundle(
self, name: str, filters: Dict[str, List[str]]
Expand Down Expand Up @@ -323,13 +318,6 @@ def __init__(
head_report_key,
)
self.head_report = self.comparison.head_report
self.cleanup()

def cleanup(self) -> None:
if self.comparison.head_report and self.comparison.head_report.db_session:
self.comparison.head_report.db_session.close()
if self.comparison.base_report and self.comparison.base_report.db_session:
self.comparison.base_report.db_session.close()

@cached_property
def bundles(self) -> List["BundleComparison"]:
Expand Down Expand Up @@ -391,7 +379,7 @@ def __init__(

def _compute_measurements(
self, measurable_name: str, measurable_ids: List[str]
) -> dict[int, Iterable[dict[Any, Any]]]:
) -> Dict[int, List[Dict[str, Any]]]:
all_measurements = measurements_by_ids(
repository=self.repository,
measurable_name=measurable_name,
Expand Down

0 comments on commit 40e1262

Please sign in to comment.