Init

Engine Initialize - Store Logic

  • packages/engine-server/src/drivers/file/storev2.ts
FileStorage {
    init {
        ...
        initNotes
    }

    initNotes {

        if metadataStore {
            // #sqlite
            new SQLiteMetadataStore 
            // download sqlite if not present
            ...
            if !isDBInitialized {
                createAllTables
                createWorkspace
            }
        }

        // 532
        vaults.map {
            notes, cacheUpdates = _initNotes(vault)
            notesWithLinks notes.filter{ n.links }
            writeNotesToCache(cacheUpdates)
        }

        // 565
        addBacklinks(notesWithLinks)
    }

        _initNotes {
            noteFiles = getAllFiles(vault)
            notes = NoteParser.parse(noteFiles, vault)
            notes.map n {
                findLinks(n)
            }
            return notes
        }

        addBacklinks(notesWithLinks, allNotes) {
            notesWithLinks.each note {
                note.links.each l {
                    n = allNotes[l.to.fname]
                    addBacklinks(n)
                }
            }
        }

}
  • src/topics/markdown/utilsv2.ts
findLinks(note) {
    ast = remark.parse(note)
    links = selectAll(wikiLink, ast)
    return links
}

NoteParser

parse

parse {
    parseFile {
    }
}

parseFile(files) {
    meta := getFileMeta
    rootNote = @parseNoteProps
    maxLvl := meta

    // 1st level notes
    lvl = 1
    prevNodes = meta[lvl]
    prevNodes.map  {
        note = @parseNoteProps it
        if !(note in $cache) { updateCache note }
        return note
    }
    prevNodes.map {
        addChild(rootNote, it)
    }
    lvl++

    // remaining notse
    while lvl < maxLvl {
        notes = meta[lvl]];
        notes.map {
            note = @parseNoteProps it
        }
    }

    // SQLiteMetadataStore
    if useSQLiteMetadataStore {
        if isVaultInitialized {
            bulkInsertAllNotes(cacheUpdates)
        } else {
            dVault.create
            bulkInsertAllNotes
        }
    }
}

parseNoteProps


parseNoteProps(vault, meta, opts, notes) {
    noteProps = file2Note(vault, meta)
    if opts.addParent {
        stubs = addParent(
            noteProps,
        )
    }
    return [noteProps].concat(stubs)
}

  • src/files.ts
getAllFiles {

}

Children
  1. V3

Backlinks