Skip to content

Commit

Permalink
ref: delete unused GroupEnvironmentWithStatsSerializer (#82090)
Browse files Browse the repository at this point in the history
last referenced in 1c8f026

<!-- Describe your PR here. -->
  • Loading branch information
asottile-sentry authored Dec 13, 2024
1 parent 3d51b11 commit 847b8d6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 55 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
54 changes: 0 additions & 54 deletions src/sentry/api/serializers/models/environment.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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

0 comments on commit 847b8d6

Please sign in to comment.