@@ -756,9 +756,8 @@ def get_fallback_ca(self, path):
756756 if not retain_distributed_pub_enabled ():
757757 return None
758758 recent_dp = (
759- self .core_distributedpublications .filter (
760- models .Q (expires_at__gte = timezone .now ()) | models .Q (expires_at__isnull = True )
761- )
759+ DistributedPublication .get_non_expired ()
760+ .filter (distribution = self )
762761 .order_by ("-pulp_created" )
763762 .select_related ("publication__repository_version" )
764763 )
@@ -881,11 +880,8 @@ class DistributedPublication(BaseModel):
881880 """
882881 Records the history of publications served by each Distribution.
883882
884- Keeps superseded publications alive and serveable for a configurable grace period
885- so clients mid-download don't receive 404 errors when a distribution switches publications.
886-
887- - ``expires_at=null`` — currently active
888- - ``expires_at=<datetime>`` — superseded; still served until that time
883+ Keeps superseded publications alive and serveable for a configurable grace period.
884+ Null `expired_at` means the publication was not superseded yet.
889885 """
890886
891887 distribution = models .ForeignKey (
@@ -897,21 +893,21 @@ class DistributedPublication(BaseModel):
897893 expires_at = models .DateTimeField (null = True )
898894
899895 @classmethod
900- def get_active (cls , distribution ):
901- """Return records that are still being served (current or within grace period)."""
902- return cls .objects .filter (distribution = distribution ).filter (
903- models .Q (expires_at__isnull = True ) | models .Q (expires_at__gte = timezone .now ())
904- )
896+ def get_non_expired (cls , include_current = True ):
897+ if include_current :
898+ return cls .objects .filter (
899+ models .Q (expires_at__isnull = True ) | models .Q (expires_at__gte = timezone .now ())
900+ )
901+ return cls .objects .filter (expires_at__gte = timezone .now ())
905902
906903 @classmethod
907- def get_expired (cls , distribution ):
908- """Return records whose grace period has elapsed for a distribution."""
909- return cls .objects .filter (distribution = distribution , expires_at__lt = timezone .now ())
904+ def get_expired (cls ):
905+ return cls .objects .filter (expires_at__lt = timezone .now ())
910906
911907 @hook (AFTER_CREATE )
912908 def cleanup (self ):
913909 """Expire older active DistributedPublications; delete already-expired ones."""
914- DistributedPublication .objects . filter ( expires_at__lt = timezone . now () ).delete ()
910+ DistributedPublication .get_expired ( ).delete ()
915911 superseded = DistributedPublication .objects .exclude (pk = self .pk ).filter (
916912 distribution = self .distribution , expires_at__isnull = True
917913 )
0 commit comments