From 847b8d6abd03add86ed991af5270ab2d98f992b4 Mon Sep 17 00:00:00 2001 From: anthony sottile <103459774+asottile-sentry@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:48:27 -0500 Subject: [PATCH] ref: delete unused GroupEnvironmentWithStatsSerializer (#82090) last referenced in 1c8f0262b62bfae89b3f74dac8ef0231103d1d81 --- pyproject.toml | 1 - .../api/serializers/models/environment.py | 54 ------------------- 2 files changed, 55 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 66c071d95ca36a..bdb63c77743d3d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -163,7 +163,6 @@ module = [ "sentry.api.permissions", "sentry.api.serializers.models.auth_provider", "sentry.api.serializers.models.dashboard", - "sentry.api.serializers.models.environment", "sentry.api.serializers.models.event", "sentry.api.serializers.models.group", "sentry.api.serializers.models.group_stream", diff --git a/src/sentry/api/serializers/models/environment.py b/src/sentry/api/serializers/models/environment.py index 5f4413f45b9013..4f69d7468d4d08 100644 --- a/src/sentry/api/serializers/models/environment.py +++ b/src/sentry/api/serializers/models/environment.py @@ -1,15 +1,7 @@ -from collections import namedtuple -from datetime import timedelta from typing import TypedDict -from django.utils import timezone - -from sentry import tsdb from sentry.api.serializers import Serializer, register from sentry.models.environment import Environment, EnvironmentProject -from sentry.tsdb.base import TSDBModel - -StatsPeriod = namedtuple("StatsPeriod", ("segments", "interval")) class EnvironmentSerializerResponse(TypedDict): @@ -39,49 +31,3 @@ def serialize( "name": obj.environment.name, "isHidden": obj.is_hidden is True, } - - -class GroupEnvironmentWithStatsSerializer(EnvironmentSerializer): - STATS_PERIODS = { - "24h": StatsPeriod(24, timedelta(hours=1)), - "30d": StatsPeriod(30, timedelta(hours=24)), - } - - def __init__(self, group, since=None, until=None): - self.group = group - self.since = since - self.until = until - - def get_attrs(self, item_list, user, **kwargs): - attrs = {item: {"stats": {}} for item in item_list} - items = {self.group.id: []} - for item in item_list: - items[self.group.id].append(item.id) - - for key, (segments, interval) in self.STATS_PERIODS.items(): - until = self.until or timezone.now() - since = self.since or until - (segments * interval) - - try: - stats = tsdb.get_frequency_series( - model=TSDBModel.frequent_environments_by_group, - items=items, - start=since, - end=until, - rollup=int(interval.total_seconds()), - ) - except NotImplementedError: - # TODO(dcramer): probably should log this, but not worth - # erring out - stats = {} - - for item in item_list: - attrs[item]["stats"][key] = [ - (k, v[item.id]) for k, v in stats.get(self.group.id, {}) - ] - return attrs - - def serialize(self, obj, attrs, user, **kwargs): - result = super().serialize(obj, attrs, user) - result["stats"] = attrs["stats"] - return result