File tree Expand file tree Collapse file tree 3 files changed +19
-5
lines changed
Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ class FolderCacheState:
6464 children_map : Mapping [Optional [uuid .UUID ], Tuple [uuid .UUID , ...]]
6565 depth_map : Mapping [uuid .UUID , int ]
6666 root_ids : Tuple [uuid .UUID , ...]
67+ root_folder_id : Optional [uuid .UUID ]
6768
6869
6970def build_folder_cache_state () -> FolderCacheState :
@@ -84,8 +85,14 @@ def build_folder_cache_state() -> FolderCacheState:
8485 }
8586
8687 children_map : defaultdict [Optional [uuid .UUID ], List [uuid .UUID ]] = defaultdict (list )
88+ root_folder_id : Optional [uuid .UUID ] = None
8789 for folder in folders :
8890 children_map [folder .parent_folder_id ].append (folder .id )
91+ if (
92+ root_folder_id is None
93+ and folder .content_type == Folder .ContentType .ROOT
94+ ):
95+ root_folder_id = folder .id
8996
9097 # Stable ordering for traversal
9198 for child_list in children_map .values ():
@@ -112,6 +119,7 @@ def _depth(current_id: uuid.UUID) -> int:
112119 ),
113120 depth_map = MappingProxyType (depth_map ),
114121 root_ids = tuple (children_map .get (None , ())),
122+ root_folder_id = root_folder_id ,
115123 )
116124
117125
Original file line number Diff line number Diff line change @@ -101,14 +101,20 @@ class Folder(NameDescriptionMixin):
101101 """
102102
103103 @staticmethod
104- def get_root_folder () -> Self :
104+ def get_root_folder () -> Self | None :
105105 """class function for general use"""
106+ try :
107+ state = get_folder_state ()
108+ root_id = getattr (state , "root_folder_id" , None )
109+ if root_id :
110+ return state .folders .get (root_id )
111+ except Exception :
112+ pass
106113 return _get_root_folder ()
107114
108115 @staticmethod
109116 def get_root_folder_id () -> uuid .UUID | None :
110- root = _get_root_folder ()
111- return root .id if root else None
117+ return getattr (Folder .get_root_folder (), "id" , None )
112118
113119 class ContentType (models .TextChoices ):
114120 """content type for a folder"""
@@ -980,7 +986,7 @@ def is_object_readable(
980986 )
981987
982988 @staticmethod
983- def get_accessible_folders (
989+ def get_accessible_folder_ids (
984990 folder : Folder ,
985991 user : User ,
986992 content_type : Folder .ContentType ,
Original file line number Diff line number Diff line change @@ -211,7 +211,7 @@ def get(self, request) -> Response:
211211 user_groups_data = list (request .user .user_groups .values ("name" , "builtin" ))
212212 user_groups = [(ug ["name" ], ug ["builtin" ]) for ug in user_groups_data ]
213213
214- accessible_domains = RoleAssignment .get_accessible_folders (
214+ accessible_domains = RoleAssignment .get_accessible_folder_ids (
215215 Folder .get_root_folder (), request .user , Folder .ContentType .DOMAIN
216216 )
217217
You can’t perform that action at this time.
0 commit comments