@@ -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 :
@@ -2685,6 +2685,18 @@ class CodebaseResource(
2685
2685
'Eg.: "/usr/bin/bash" for a path of "tarball-extract/rootfs/usr/bin/bash"'
2686
2686
),
2687
2687
)
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
+
2688
2700
status = models .CharField (
2689
2701
blank = True ,
2690
2702
max_length = 50 ,
@@ -2778,6 +2790,7 @@ class Meta:
2778
2790
models .Index (fields = ["compliance_alert" ]),
2779
2791
models .Index (fields = ["is_binary" ]),
2780
2792
models .Index (fields = ["is_text" ]),
2793
+ models .Index (fields = ["project" , "parent_path" ]),
2781
2794
]
2782
2795
constraints = [
2783
2796
models .UniqueConstraint (
@@ -2790,6 +2803,11 @@ class Meta:
2790
2803
def __str__ (self ):
2791
2804
return self .path
2792
2805
2806
+ def save (self , * args , ** kwargs ):
2807
+ if self .path and not self .parent_path :
2808
+ self .parent_path = self .parent_directory ()
2809
+ super ().save (* args , ** kwargs )
2810
+
2793
2811
@property
2794
2812
def location_path (self ):
2795
2813
"""Return the location of the resource as a Path instance."""
@@ -2857,7 +2875,8 @@ def get_path_segments_with_subpath(self):
2857
2875
2858
2876
def parent_directory (self ):
2859
2877
"""Return the parent path for this CodebaseResource or None."""
2860
- return parent_directory (self .path , with_trail = False )
2878
+ parent_path = parent_directory (str (self .path ), with_trail = False )
2879
+ return parent_path or None
2861
2880
2862
2881
def has_parent (self ):
2863
2882
"""
0 commit comments