@@ -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 :
@@ -2688,6 +2688,18 @@ class CodebaseResource(
26882688 'Eg.: "/usr/bin/bash" for a path of "tarball-extract/rootfs/usr/bin/bash"'
26892689 ),
26902690 )
2691+
2692+ parent_path = models .CharField (
2693+ max_length = 2000 ,
2694+ null = True ,
2695+ blank = True ,
2696+ help_text = _ (
2697+ "The path of the resource's parent directory. "
2698+ "Set to None for top-level (root) resources. "
2699+ "Used to efficiently retrieve a directory's contents."
2700+ ),
2701+ )
2702+
26912703 status = models .CharField (
26922704 blank = True ,
26932705 max_length = 50 ,
@@ -2781,6 +2793,7 @@ class Meta:
27812793 models .Index (fields = ["compliance_alert" ]),
27822794 models .Index (fields = ["is_binary" ]),
27832795 models .Index (fields = ["is_text" ]),
2796+ models .Index (fields = ["project" , "parent_path" ]),
27842797 ]
27852798 constraints = [
27862799 models .UniqueConstraint (
@@ -2793,6 +2806,11 @@ class Meta:
27932806 def __str__ (self ):
27942807 return self .path
27952808
2809+ def save (self , * args , ** kwargs ):
2810+ if self .path and not self .parent_path :
2811+ self .parent_path = self .parent_directory ()
2812+ super ().save (* args , ** kwargs )
2813+
27962814 def get_absolute_url (self ):
27972815 return reverse ("resource_detail" , args = [self .project .slug , self .path ])
27982816
@@ -2863,7 +2881,8 @@ def get_path_segments_with_subpath(self):
28632881
28642882 def parent_directory (self ):
28652883 """Return the parent path for this CodebaseResource or None."""
2866- return parent_directory (self .path , with_trail = False )
2884+ parent_path = parent_directory (str (self .path ), with_trail = False )
2885+ return parent_path or None
28672886
28682887 def has_parent (self ):
28692888 """
0 commit comments