Skip to content

Commit

Permalink
speedup latestUid algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
WeeJeWel committed Aug 22, 2024
1 parent e116f56 commit ae8cc26
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/GoogleBackupMail.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,18 @@ export default class GoogleBackupMail {
// Get the latest downloaded UID
const latestUid = await fse.readdir(filepath)
.then(files => {
const uids = files
.filter(file => file.endsWith('.eml'))
.map(file => Number.parseInt(file));

if (uids.length === 0) {
return 0;
}
let latestUid = 0;

uids.sort((a, b) => b - a);
return uids[0];
files
.filter(file => file.endsWith('.eml'))
.map(file => Number.parseInt(file))
.forEach(uid => {
if (uid > latestUid) {
latestUid = uid;
}
});

return latestUid;
});

this.log(`🗄️ Latest UID: ${latestUid}`);
Expand Down

0 comments on commit ae8cc26

Please sign in to comment.