@@ -229,7 +229,7 @@ def delete(self, *args, **kwargs):
229
229
Note that projects with queued or running pipeline runs cannot be deleted.
230
230
See the `_raise_if_run_in_progress` method.
231
231
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.
233
233
"""
234
234
with suppress (redis .exceptions .ConnectionError , AttributeError ):
235
235
if self .status == self .Status .RUNNING :
@@ -2688,6 +2688,18 @@ class CodebaseResource(
2688
2688
'Eg.: "/usr/bin/bash" for a path of "tarball-extract/rootfs/usr/bin/bash"'
2689
2689
),
2690
2690
)
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
+
2691
2703
status = models .CharField (
2692
2704
blank = True ,
2693
2705
max_length = 50 ,
@@ -2781,6 +2793,7 @@ class Meta:
2781
2793
models .Index (fields = ["compliance_alert" ]),
2782
2794
models .Index (fields = ["is_binary" ]),
2783
2795
models .Index (fields = ["is_text" ]),
2796
+ models .Index (fields = ["project" , "parent_path" ]),
2784
2797
]
2785
2798
constraints = [
2786
2799
models .UniqueConstraint (
@@ -2793,6 +2806,11 @@ class Meta:
2793
2806
def __str__ (self ):
2794
2807
return self .path
2795
2808
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
+
2796
2814
def get_absolute_url (self ):
2797
2815
return reverse ("resource_detail" , args = [self .project .slug , self .path ])
2798
2816
@@ -2863,7 +2881,8 @@ def get_path_segments_with_subpath(self):
2863
2881
2864
2882
def parent_directory (self ):
2865
2883
"""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
2867
2886
2868
2887
def has_parent (self ):
2869
2888
"""
0 commit comments