@@ -229,7 +229,7 @@ def delete(self, *args, **kwargs):
229229 Note that projects with queued or running pipeline runs cannot be deleted.
230230 See the `_raise_if_run_in_progress` method.
231231 The following if statements should not be triggered unless the `.delete()`
232- method is directly call from an instance of this class.
232+ method is directly call from a instance of this class.
233233 """
234234 with suppress (redis .exceptions .ConnectionError , AttributeError ):
235235 if self .status == self .Status .RUNNING :
@@ -2685,6 +2685,18 @@ class CodebaseResource(
26852685 'Eg.: "/usr/bin/bash" for a path of "tarball-extract/rootfs/usr/bin/bash"'
26862686 ),
26872687 )
2688+
2689+ parent_path = models .CharField (
2690+ max_length = 2000 ,
2691+ null = True ,
2692+ blank = True ,
2693+ help_text = _ (
2694+ "The path of the resource's parent directory. "
2695+ "Set to None for top-level (root) resources. "
2696+ "Used to efficiently retrieve a directory's contents."
2697+ ),
2698+ )
2699+
26882700 status = models .CharField (
26892701 blank = True ,
26902702 max_length = 50 ,
@@ -2772,6 +2784,7 @@ class Meta:
27722784 models .Index (fields = ["compliance_alert" ]),
27732785 models .Index (fields = ["is_binary" ]),
27742786 models .Index (fields = ["is_text" ]),
2787+ models .Index (fields = ["project" , "parent_path" ]),
27752788 ]
27762789 constraints = [
27772790 models .UniqueConstraint (
@@ -2784,6 +2797,11 @@ class Meta:
27842797 def __str__ (self ):
27852798 return self .path
27862799
2800+ def save (self , * args , ** kwargs ):
2801+ if self .path and not self .parent_path :
2802+ self .parent_path = self .parent_directory ()
2803+ super ().save (* args , ** kwargs )
2804+
27872805 @property
27882806 def location_path (self ):
27892807 """Return the location of the resource as a Path instance."""
@@ -2851,7 +2869,8 @@ def get_path_segments_with_subpath(self):
28512869
28522870 def parent_directory (self ):
28532871 """Return the parent path for this CodebaseResource or None."""
2854- return parent_directory (self .path , with_trail = False )
2872+ parent_path = parent_directory (str (self .path ), with_trail = False )
2873+ return parent_path or None
28552874
28562875 def has_parent (self ):
28572876 """
0 commit comments