Fix #181 - Making sure that documents have a .path
Though they should...
This commit is contained in:
@@ -138,9 +138,17 @@ class CacheManager {
|
|||||||
public async addToLiveCache(path: string): Promise<void> {
|
public async addToLiveCache(path: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const doc = await getAndMapIndexedDocument(path)
|
const doc = await getAndMapIndexedDocument(path)
|
||||||
|
if (!doc.path) {
|
||||||
|
console.error(
|
||||||
|
`Missing .path field in IndexedDocument "${doc.basename}", skipping`
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
this.documents.set(path, doc)
|
this.documents.set(path, doc)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Omnisearch: Error while adding to live cache', e)
|
console.warn(`Omnisearch: Error while adding "${path}" to live cache`, e)
|
||||||
|
// Shouldn't be needed, but...
|
||||||
|
this.removeFromLiveCache(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,9 +95,11 @@ export class Omnisearch {
|
|||||||
* @param paths
|
* @param paths
|
||||||
*/
|
*/
|
||||||
public async addFromPaths(paths: string[]): Promise<void> {
|
public async addFromPaths(paths: string[]): Promise<void> {
|
||||||
let documents = await Promise.all(
|
let documents = (
|
||||||
paths.map(async path => await cacheManager.getDocument(path))
|
await Promise.all(
|
||||||
)
|
paths.map(async path => await cacheManager.getDocument(path))
|
||||||
|
)
|
||||||
|
).filter(d => !!d?.path)
|
||||||
|
|
||||||
// If a document is already added, discard it
|
// If a document is already added, discard it
|
||||||
this.removeFromPaths(
|
this.removeFromPaths(
|
||||||
|
|||||||
Reference in New Issue
Block a user