Skip to content

Commit fe9ae03

Browse files
committed
inside getFoldersRecusively method prevent same db call multiple times (#47)
Signed-off-by: Dae❤️ <74119677+daeisbae@users.noreply.github.com>
1 parent d07a956 commit fe9ae03

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/service/get-db.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ export class FetchRepoService {
2929
if (!repositoryData) return null
3030

3131
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+
3236
const folders: FullFolder[] = branchData
33-
? await this.getFoldersRecursively(branchData.branch_id, null)
37+
? await this.getFoldersRecursively(null, allFolders)
3438
: []
3539

3640
return {
@@ -41,11 +45,9 @@ export class FetchRepoService {
4145
}
4246

4347
private async getFoldersRecursively(
44-
branchId: number,
45-
parentFolderId: number | null
48+
parentFolderId: number | null,
49+
allFolders: FolderData[]
4650
): Promise<FullFolder[]> {
47-
const allFolders = await this.folder.select(branchId)
48-
if (!allFolders) throw new Error('No folders found for the repository')
4951

5052
const currentLevel = allFolders.filter(
5153
(f) => f.parent_folder_id === parentFolderId
@@ -56,8 +58,8 @@ export class FetchRepoService {
5658
const foldersWithChildren: FullFolder[] = []
5759
for (const folder of currentLevel) {
5860
const subfolders = await this.getFoldersRecursively(
59-
branchId,
60-
folder.folder_id
61+
folder.folder_id,
62+
allFolders
6163
)
6264

6365
const files = await this.file.select(folder.folder_id)

0 commit comments

Comments
 (0)