Skip to content

Commit d714ada

Browse files
committed
Find Current PoC via Unique Non-Moved Status
By creating the poc_enforce_maxoneoutcome_idx unique partial index we have ensured that every Patch has only one current commitfest defined by having a status that isn't Moved. Update Patch to find this PoC via the index and then return its commitfest property for current_commitfest (and note the method as being deprecated).
1 parent 75252c1 commit d714ada

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pgcommitfest/commitfest/models.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.contrib.auth.models import User
22
from django.db import models
3+
from django.db.models import Q
34
from django.shortcuts import get_object_or_404
45

56
from datetime import datetime
@@ -178,13 +179,16 @@ class Patch(models.Model, DiffableModel):
178179
"authors": "authors_string",
179180
"reviewers": "reviewers_string",
180181
}
181-
182+
# XXX probably should just encourage using PoC.commitfest since most places
183+
# dealing with the Patch need the PoC anyway.
182184
def current_commitfest(self):
183-
return self.commitfests.order_by("-patchoncommitfest__enterdate").first()
185+
return self.current_patch_on_commitfest().commitfest
184186

185187
def current_patch_on_commitfest(self):
186-
cf = self.current_commitfest()
187-
return get_object_or_404(PatchOnCommitFest, patch=self, commitfest=cf)
188+
# The unique partial index poc_enforce_maxoneoutcome_idx stores the PoC
189+
# No caching here (inside the instance) since the caller should just need
190+
# the PoC once per request.
191+
return get_object_or_404(PatchOnCommitFest, Q(patch=self) & ~Q(status=PatchOnCommitFest.STATUS_NEXT))
188192

189193
# Some accessors
190194
@property

0 commit comments

Comments
 (0)