Skip to content

Commit

Permalink
make indexing function fully async
Browse files Browse the repository at this point in the history
  • Loading branch information
samlhuillier committed Nov 30, 2023
1 parent c4518a5 commit 899da7d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions electron/main/database/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,22 @@ export const maybeRePopulateTable = async (
) => {
const filesInfoList = GetFilesInfoList(directoryPath, extensionsToFilterFor);

for (const fileInfo of filesInfoList) {
const checkAndConvertPromises = filesInfoList.map(async (fileInfo) => {
const isFileInDBResult = await isFileInDB(table, fileInfo.path);
if (!isFileInDBResult) {
const dbEntry = convertFileTypeToDBType(fileInfo);
await table.add([dbEntry]);
return convertFileTypeToDBType(fileInfo);
}
}
return null;
});

const results = await Promise.all(checkAndConvertPromises);

// Use a type guard to filter out null values
const entriesToAdd: RagnoteDBEntry[] = results.filter(
(entry): entry is RagnoteDBEntry => entry !== null
);

await table.add(entriesToAdd);
};

const isFileInDB = async (
Expand Down

0 comments on commit 899da7d

Please sign in to comment.