Implement 'occurs_in_last_release'

This commit is contained in:
Klaas van Schelven
2024-09-12 09:49:22 +02:00
parent a198eaf9df
commit e59fd3a225
3 changed files with 8 additions and 4 deletions

View File

@@ -97,7 +97,9 @@ class Issue(models.Model):
]
def occurs_in_last_release(self):
return False # TODO actually implement (and then: implement in a performant manner)
# we can depend on latest_release to exist, because we always create at least one release, even for 'no release'
latest_release = self.project.get_latest_release()
return latest_release.version in self.events_at
def turningpoint_set_all(self):
# like turningpoint_set.all() but with user in select_related

View File

@@ -75,7 +75,7 @@
<div class="dropdown-content-right flex-col pl-2">
{# note that an if-statement ("issue.occurs_in_last_release") is missing here, because we're not on the level of a single issue #}
{# handling of that question (but per-issue, and after-click) is left as a TODO on the view #}
{# handling of that question (but per-issue, and after-click) is done in views.py, _q_for_invalid_for_action() #}
<button name="action" value="resolved_release:{{ project.get_latest_release.version }}" class="block self-stretch font-bold text-slate-500 border-slate-300 pl-4 pr-4 pb-2 pt-2 border-l-2 border-r-2 border-b-2 bg-white hover:bg-slate-200 active:ring text-left whitespace-nowrap">Resolved in latest ({{ project.get_latest_release.get_short_version }})</button>
</div>
</div>

View File

@@ -84,10 +84,12 @@ class Project(models.Model):
models.Index(fields=["id", "sentry_key"]),
]
"""
def get_latest_release(self):
# TODO perfomance considerations... this can be denormalized/cached at the project level
from releases.models import ordered_releases
return list(ordered_releases(project=self))[-1]
if not hasattr(self, "_latest_release"):
self._latest_release = list(ordered_releases(project=self))[-1]
return self._latest_release
def save(self, *args, **kwargs):
if self.slug in [None, ""]: