Skip to content

Commit aaa0702

Browse files
committed
feat: speed up scanning
1 parent 378ac96 commit aaa0702

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎src/MediaScanner.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ export class MediaScanner extends EventEmitter {
6262

6363
this.emit(MediaScanner.events.start, total)
6464

65+
const documents = await this.media.all()
66+
6567
const files = await Throttle(
6668
filtered.map((filename, index) => async () => {
6769
try {
6870
const id = fs.basename(filename, false)
6971

70-
if (await this.media.exists(id)) {
72+
if (documents.map((doc) => doc?._id).includes(id)) {
7173
const document = await this.media.get(id)
7274
return this.convertible(filename, document, index, total)
7375
}

‎src/MediaStore.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export class MediaStore {
2828
this.log = logger.extend('storage')
2929
}
3030

31+
async all() {
32+
const docs = await this.database.allDocs<MediaInfo>()
33+
return docs.rows.map(row => row.doc)
34+
}
35+
3136
async exists(id: string) {
3237
try {
3338
const document = await this.database.get<MediaInfo>(id)

0 commit comments

Comments
 (0)