From 1159ed9dfc2e59beaba8efa7467182a210ac04ea Mon Sep 17 00:00:00 2001 From: amit <1mitccc@gmail.com> Date: Sat, 21 Dec 2024 07:02:27 +0530 Subject: [PATCH] fix: googledrive: only sync files for new folders --- .../folder/services/googledrive/index.ts | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/api/src/filestorage/folder/services/googledrive/index.ts b/packages/api/src/filestorage/folder/services/googledrive/index.ts index 19500d018..0fa573ceb 100644 --- a/packages/api/src/filestorage/folder/services/googledrive/index.ts +++ b/packages/api/src/filestorage/folder/services/googledrive/index.ts @@ -129,8 +129,8 @@ export class GoogleDriveFolderService implements IFolderService { }); const lastSyncTime = await this.getLastSyncTime(connection.id_connection); - - const folders = lastSyncTime + const isFirstSync = !lastSyncTime; + const folders = isFirstSync ? await this.getFoldersIncremental( auth, connection.id_connection, @@ -141,12 +141,6 @@ export class GoogleDriveFolderService implements IFolderService { connection.id_connection, ); - const filesToSync = await this.getFilesToSyncForFolders( - folders, - connection.id_connection, - auth, - ); - // Sync permissions for folders await this.ingestPermissionsForFolders(folders, connection.id_connection); @@ -161,7 +155,18 @@ export class GoogleDriveFolderService implements IFolderService { this.logger.log(`Synced ${folders.length} Google Drive folders!`); // Sync files from new folders - await this.fileService.ingestFiles(filesToSync, connection.id_connection); + if (!isFirstSync) { + const filesToSync = await this.getFilesToSyncForFolders( + folders, + connection.id_connection, + auth, + ); + await this.fileService.ingestFiles( + filesToSync, + connection.id_connection, + ); + } + return { data: [], message: 'Google Drive folders retrieved',