Skip to content

Commit

Permalink
refactor: remove getUnresolvedFolders method and simplify folder proc…
Browse files Browse the repository at this point in the history
…essing in GoogleDriveFolderService
  • Loading branch information
amuwal committed Dec 18, 2024
1 parent 758da8a commit 63560e1
Showing 1 changed file with 1 addition and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,8 @@ export class GoogleDriveFolderService implements IFolderService {
this.getModifiedFolders(drive, lastSyncTime),
);

const unresolvedFolders = await this.getUnresolvedFolders(connectionId);
return await this.processFoldersWithParents(
modifiedFolders.concat(unresolvedFolders),
modifiedFolders,
connectionId,
driveIds,
drive,
Expand Down Expand Up @@ -644,47 +643,6 @@ export class GoogleDriveFolderService implements IFolderService {
return folders;
}

private async getUnresolvedFolders(
connectionId: string,
): Promise<GoogleDriveFolderOutput[]> {
// Get unresolved folders
const unresolvedFolders = await this.prisma.fs_folders.findMany({
where: {
id_connection: connectionId,
parent_folder: 'unresolved',
},
select: {
id_fs_folder: true,
name: true,
},
});

// Get remote data for all folders in a single query
const folderIds = unresolvedFolders.map((folder) => folder.id_fs_folder);
const remoteDataEntries = await this.prisma.remote_data.findMany({
where: {
ressource_owner_id: {
in: folderIds,
},
},
});

// Create a map for quick lookup
const remoteDataMap = new Map(
remoteDataEntries.map((entry) => [entry.ressource_owner_id, entry.data]),
);

// Map and parse the remote data, filtering out any null values
return unresolvedFolders
.map((folder) => {
const remoteData = remoteDataMap.get(folder.id_fs_folder);
return remoteData
? (JSON.parse(remoteData) as GoogleDriveFolderOutput)
: null;
})
.filter((folder): folder is GoogleDriveFolderOutput => folder !== null);
}

private async getLastSyncTime(connectionId: string): Promise<Date | null> {
const lastSync = await this.prisma.fs_folders.findFirst({
where: { id_connection: connectionId },
Expand Down

0 comments on commit 63560e1

Please sign in to comment.