From 7c28b0bed5d71207e3c01d32e5e0667a9dad7127 Mon Sep 17 00:00:00 2001 From: amit <1mitccc@gmail.com> Date: Tue, 24 Dec 2024 08:59:27 +0530 Subject: [PATCH] fix: gooledrive: update remote cursor even if no files are updated --- .../file/services/googledrive/index.ts | 88 ++++++++----------- 1 file changed, 37 insertions(+), 51 deletions(-) diff --git a/packages/api/src/filestorage/file/services/googledrive/index.ts b/packages/api/src/filestorage/file/services/googledrive/index.ts index 320928b3e..33a220cda 100644 --- a/packages/api/src/filestorage/file/services/googledrive/index.ts +++ b/packages/api/src/filestorage/file/services/googledrive/index.ts @@ -60,65 +60,49 @@ export class GoogleDriveService implements IFileService { ), ); - if (permissionsIds.length === 0) { - this.logger.log('No permissions found in the provided files.'); - return this.ingestService.ingestData< - UnifiedFilestorageFileOutput, - GoogleDriveFileOutput - >( + if (permissionsIds.length) { + const uniquePermissions = await this.fetchPermissions( + permissionsIds, sourceData, + drive, + ); + + // Ingest permissions using the ingestService + const syncedPermissions = await this.ingestService.ingestData< + UnifiedFilestoragePermissionOutput, + GoogledrivePermissionOutput + >( + uniquePermissions, 'googledrive', connectionId, 'filestorage', - 'file', - customFieldMappings, - extraParams, + 'permission', ); - } - - const uniquePermissions = await this.fetchPermissions( - permissionsIds, - sourceData, - drive, - ); - // Ingest permissions using the ingestService - const syncedPermissions = await this.ingestService.ingestData< - UnifiedFilestoragePermissionOutput, - GoogledrivePermissionOutput - >( - uniquePermissions, - 'googledrive', - connectionId, - 'filestorage', - 'permission', - ); - - this.logger.log( - `Ingested ${uniquePermissions.length} permissions for googledrive files.`, - ); - - // Create a map of original permission ID to synced permission ID - const permissionIdMap: Map = new Map( - syncedPermissions.map((permission) => [ - permission.remote_id, - permission.id_fs_permission, - ]), - ); + this.logger.log( + `Ingested ${uniquePermissions.length} permissions for googledrive files.`, + ); - // Update each file's permissions with the synced permission IDs - sourceData.forEach((file) => { - if (file.permissionIds?.length) { - file.internal_permissions = file.permissionIds - .map((permissionId) => permissionIdMap.get(permissionId)) - .filter( - (permissionId): permissionId is string => - permissionId !== undefined, - ); - } - }); + // Create a map of original permission ID to synced permission ID + const permissionIdMap: Map = new Map( + syncedPermissions.map((permission) => [ + permission.remote_id, + permission.id_fs_permission, + ]), + ); - await this.assignDriveIds(sourceData, drive); + // Update each file's permissions with the synced permission IDs + sourceData.forEach((file) => { + if (file.permissionIds?.length) { + file.internal_permissions = file.permissionIds + .map((permissionId) => permissionIdMap.get(permissionId)) + .filter( + (permissionId): permissionId is string => + permissionId !== undefined, + ); + } + }); + } // Ingest files with updated permissions const syncedFiles = await this.ingestService.ingestData< @@ -138,6 +122,8 @@ export class GoogleDriveService implements IFileService { `Ingested a batch of ${syncedFiles.length} googledrive files.`, ); + await this.assignDriveIds(sourceData, drive); + if (remote_cursor) { await this.prisma.fs_drives.updateMany({ where: {