@@ -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 ,
@@ -2772,6 +2784,7 @@ class Meta:
2772
2784
models .Index (fields = ["compliance_alert" ]),
2773
2785
models .Index (fields = ["is_binary" ]),
2774
2786
models .Index (fields = ["is_text" ]),
2787
+ models .Index (fields = ["project" , "parent_path" ]),
2775
2788
]
2776
2789
constraints = [
2777
2790
models .UniqueConstraint (
@@ -2784,6 +2797,11 @@ class Meta:
2784
2797
def __str__ (self ):
2785
2798
return self .path
2786
2799
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
+
2787
2805
@property
2788
2806
def location_path (self ):
2789
2807
"""Return the location of the resource as a Path instance."""
@@ -2851,7 +2869,8 @@ def get_path_segments_with_subpath(self):
2851
2869
2852
2870
def parent_directory (self ):
2853
2871
"""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
2855
2874
2856
2875
def has_parent (self ):
2857
2876
"""
0 commit comments