Skip to content

Commit

Permalink
add get_or_create_grouphashes helper
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Aug 16, 2024
1 parent a6bc84b commit 74c288f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/sentry/grouping/ingest/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import sentry_sdk

from sentry import options
from sentry.exceptions import HashDiscarded
from sentry.features.rollout import in_random_rollout
from sentry.grouping.api import (
Expand All @@ -27,6 +28,7 @@
from sentry.grouping.ingest.utils import extract_hashes
from sentry.grouping.result import CalculatedHashes
from sentry.models.grouphash import GroupHash
from sentry.models.grouphashmetadata import GroupHashMetadata
from sentry.models.project import Project
from sentry.utils import metrics
from sentry.utils.metrics import MutableTags
Expand Down Expand Up @@ -340,3 +342,22 @@ def get_hash_values(
job["finest_tree_label"] = all_hashes.finest_tree_label

return (primary_hashes, secondary_hashes, all_hashes)


def get_or_create_grouphashes(
project: Project, calculated_hashes: CalculatedHashes
) -> list[GroupHash]:
grouphashes = []

for hash_value in extract_hashes(calculated_hashes):
grouphash, created = GroupHash.objects.get_or_create(project=project, hash=hash_value)

# TODO: Do we want to expand this to backfill metadata for existing grouphashes? If we do,
# we'll have to override the metadata creation date for them.
if created and options.get("grouping.grouphash_metadata.ingestion_writes_enabled"):
# For now, this just creates a record with a creation timestamp
GroupHashMetadata.objects.create(grouphash=grouphash)

grouphashes.append(grouphash)

return grouphashes

0 comments on commit 74c288f

Please sign in to comment.