Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migration(shared-views): Add visibility column to groupsearchview table #86440

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 5.1.5 on 2025-03-03 23:44

from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration


class Migration(CheckedMigration):
# This flag is used to mark that a migration shouldn't be automatically run in production.
# This should only be used for operations where it's safe to run the migration after your
# code has deployed. So this should not be used for most operations that alter the schema
# of a table.
# Here are some things that make sense to mark as post deployment:
# - Large data migrations. Typically we want these to be run manually so that they can be
# monitored and not block the deploy for a long period of time while they run.
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
# run this outside deployments so that we don't block them. Note that while adding an index
# is a schema change, it's completely safe to run the operation after the code has deployed.
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment

is_post_deployment = False

dependencies = [
("sentry", "0838_backfill_groupsearchview_positions_to_gsvstarred"),
]

operations = [
migrations.AddField(
model_name="groupsearchview",
name="visibility",
field=models.CharField(default="owner", max_length=16),
),
]
19 changes: 19 additions & 0 deletions src/sentry/models/groupsearchview.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing import Any

from django.db import models
from django.db.models import UniqueConstraint
from django.utils.translation import gettext_lazy as _

from sentry.backup.scopes import RelocationScope
from sentry.constants import ENVIRONMENT_NAME_MAX_LENGTH
Expand All @@ -26,6 +29,18 @@ class Meta:
unique_together = (("group_search_view", "project"),)


class Visibility:
ORGANIZATION = "organization"
OWNER = "owner"

@classmethod
def as_choices(cls) -> list[tuple[str, Any]]:
return [
(cls.ORGANIZATION, _("Organization")),
(cls.OWNER, _("Only for me")),
]


@region_silo_model
class GroupSearchView(DefaultFieldsModelExisting):
"""
Expand All @@ -37,6 +52,10 @@ class GroupSearchView(DefaultFieldsModelExisting):
user_id = HybridCloudForeignKey("sentry.User", on_delete="CASCADE")
organization = FlexibleForeignKey("sentry.Organization")

visibility = models.CharField(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think using a CharField is fine here, but at what scale would it make sense to use an integer mapping for this instead? e.g

class GroupStatus:
?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question that I'm not really sure how to answer. To me, it seems like the only benefit of switching to an integer mapping is marginally better performance in a couple niche areas. It's hard to draw a line for when those performance improvements actually warrant a refactor. What do you think?

Copy link
Member

@JoshFerge JoshFerge Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, if we did high volume queries and needed to eek out a bit more performance, it would help with that. in addition, it saves a small amount of data, which could be important if this table needed to scale to billions of rows. likely not, but something to consider for bigger tables (e.g. anything to do with GroupedMessage).

given that this view in general will be constrained by user action and never grow that large, it is probably safe to assume that our current char based column will be fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A char column will be fine for this kind of table. It is unlikely to reach billions of rows.

max_length=16, default=Visibility.OWNER, choices=Visibility.as_choices()
)

query = models.TextField()
query_sort = models.CharField(
max_length=16, default=SortOptions.DATE, choices=SortOptions.as_choices()
Expand Down
Loading