Skip to content

Commit

Permalink
fix: googledrive: only sync files for new folders
Browse files Browse the repository at this point in the history
  • Loading branch information
amuwal committed Dec 21, 2024
1 parent df479e8 commit 1159ed9
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/api/src/filestorage/folder/services/googledrive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand All @@ -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',
Expand Down

0 comments on commit 1159ed9

Please sign in to comment.