@@ -29,8 +29,12 @@ export class FetchRepoService {
29
29
if ( ! repositoryData ) return null
30
30
31
31
const branchData = await this . branch . select ( repositoryData . url )
32
+
33
+ const allFolders = await this . folder . select ( branchData ! . branch_id )
34
+ if ( ! allFolders ) return null
35
+
32
36
const folders : FullFolder [ ] = branchData
33
- ? await this . getFoldersRecursively ( branchData . branch_id , null )
37
+ ? await this . getFoldersRecursively ( null , allFolders )
34
38
: [ ]
35
39
36
40
return {
@@ -41,11 +45,9 @@ export class FetchRepoService {
41
45
}
42
46
43
47
private async getFoldersRecursively (
44
- branchId : number ,
45
- parentFolderId : number | null
48
+ parentFolderId : number | null ,
49
+ allFolders : FolderData [ ]
46
50
) : Promise < FullFolder [ ] > {
47
- const allFolders = await this . folder . select ( branchId )
48
- if ( ! allFolders ) throw new Error ( 'No folders found for the repository' )
49
51
50
52
const currentLevel = allFolders . filter (
51
53
( f ) => f . parent_folder_id === parentFolderId
@@ -56,8 +58,8 @@ export class FetchRepoService {
56
58
const foldersWithChildren : FullFolder [ ] = [ ]
57
59
for ( const folder of currentLevel ) {
58
60
const subfolders = await this . getFoldersRecursively (
59
- branchId ,
60
- folder . folder_id
61
+ folder . folder_id ,
62
+ allFolders
61
63
)
62
64
63
65
const files = await this . file . select ( folder . folder_id )
0 commit comments