Squashed commit of the following:

commit 739f9c349031510e8ef010ba2445a2a1fdbec247
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Sun Oct 16 16:57:03 2022 +0200

    Code cleaning + README

commit 85762bae592f3eafd34ba22b0cf1841bfbd91ca6
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Sun Oct 16 14:59:01 2022 +0200

    Cleaning deleted PDFs from cache

commit 1a37bf38d3f64870d4b40df1b67d8106c893ab64
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Sun Oct 16 13:18:06 2022 +0200

    PDF cache saved to IndexedDB
This commit is contained in:
Simon Cambier
2022-10-16 16:58:10 +02:00
parent ad820cb2c9
commit 1c3cc728f6
13 changed files with 184 additions and 124 deletions

View File

@@ -5,12 +5,12 @@ import { deflate, inflate } from 'pako'
import {
notesCacheFilePath,
minisearchCacheFilePath,
type IndexedNote,
type IndexedDocument,
} from './globals'
import { settings } from './settings'
class CacheManager {
notesCache: Record<string, IndexedNote> = {}
notesCache: Record<string, IndexedDocument> = {}
compress = true
writeInterval = 5_000 // In milliseconds
@@ -94,7 +94,7 @@ class CacheManager {
console.log('Omnisearch - Notes cache saved on disk')
}
public addNoteToCache(path: string, note: IndexedNote) {
public addNoteToCache(path: string, note: IndexedDocument) {
this.notesCache[path] = note
this.saveNotesCache()
}
@@ -103,11 +103,11 @@ class CacheManager {
delete this.notesCache[key]
}
public getNoteFromCache(key: string): IndexedNote | undefined {
public getNoteFromCache(key: string): IndexedDocument | undefined {
return this.notesCache[key]
}
public getNonExistingNotesFromCache(): IndexedNote[] {
public getNonExistingNotesFromCache(): IndexedDocument[] {
return Object.values(this.notesCache).filter(note => note.doesNotExist)
}