Documentation
¶
Index ¶
- Constants
- Variables
- func BatchGetBlockAttrs(ids []string) (ret map[string]map[string]string)
- func BatchGetBlockAttrsWitTrees(ids []string, trees map[string]*parse.Tree) (ret map[string]map[string]string)
- func BatchRemoveAssetsQueue(hashes []string)
- func BatchRemoveTreeQueue(rootIDs []string)
- func CacheRef(tree *parse.Tree, refNode *ast.Node)
- func CalculateEmbedBlockContent(block *Block) (content string, supported bool)
- func CheckAssetContentReadonlyStatement(stmt string) error
- func CheckHistoryReadonlyStatement(stmt string) error
- func CheckReadonlyBlockQueryStatement(stmt, boxID string) error
- func CheckReadonlyStatement(stmt string) error
- func CheckReadonlyStatementInBox(stmt, boxID string) error
- func CheckSingleStatement(stmt string) error
- func ClearCache()
- func ClearQueue()
- func CloseDatabase()
- func CloseEncryptedDB(boxID string)
- func DefRefs(condition string, limit int) (ret []map[*Block]*Block)
- func DeleteAssetContentsByPathQueue(path string)
- func DeleteBoxQueue(boxID string)
- func DeleteBoxRefsQueue(boxID string)
- func DeleteOutdatedHistories(before int64)
- func DeleteRefsTreeQueue(tree *parse.Tree)
- func Exec(stmt string, args ...any) error
- func ExistRefByDefIDs(defIDs, defRootIDs, excludeBlockIDs, excludeRootIDs []string) (ret bool, err error)
- func ExistRefByDefIDsInBox(defIDs, defRootIDs, excludeBlockIDs, excludeRootIDs []string, boxID string) (ret bool, err error)
- func FillAttributeViewNilValue(value *av.Value, typ av.KeyType)
- func FillAttributeViewTemplateValuesForKeysWithContext(attrView *av.AttributeView, view *av.View, collection av.Collection, ...)
- func FillAttributeViewTemplateValuesWithContext(attrView *av.AttributeView, view *av.View, collection av.Collection, ...)
- func FilterNonEmptyRefCheckIDs(ids []string) (ret []string)
- func FilterVirtualRefKeywordsByAccess(keywords []string, boxID string, accessible func(string, string) bool) (ret []string)
- func FlushAssetContentQueue() error
- func FlushAssetContentTxJob()
- func FlushHistoryQueue()
- func FlushHistoryTxJob()
- func FlushQueue()
- func FlushTxJob()
- func GetBlockAttrs(id string) (ret map[string]string)
- func GetContainerText(container *ast.Node) string
- func GetDuplicatedRootIDs(blocksTable string) (ret []string)
- func GetEncryptedBoxIDs() (ret []string)
- func GetEncryptedDB(boxID string) *sql.DB
- func GetFurtherCollections(attrView *av.AttributeView, cachedAttrViews map[string]*av.AttributeView) map[string]*av.RollupRenderContext
- func GetFurtherCollectionsWithContext(attrView *av.AttributeView, cachedAttrViews map[string]*av.AttributeView, ...) map[string]*av.RollupRenderContext
- func GetRefDuplicatedDefRootIDs() (ret []string)
- func GetRefText(defBlockID string) (ret string)
- func GetRootUpdated() (ret map[string]string, err error)
- func GetTemplateKeyRelevantKeys(attrView *av.AttributeView, templateKey *av.Key) (ret []*av.Key)
- func GetTemplateKeysByResolutionOrder(attrView *av.AttributeView) (ret []*av.Key, resolved bool)
- func HasDocumentRefsOutsideRootsInBox(rootID string, owned map[string]bool, boxID string) (bool, error)
- func IndexAssetContentsQueue(assetContents []*AssetContent)
- func IndexHistoriesQueue(histories []*History)
- func IndexNodeQueue(id string)
- func IndexQueueIdle() bool
- func IndexRecoveryPending() bool
- func IndexTreeQueue(tree *parse.Tree)
- func InitAssetContentDatabase(forceRebuild bool) error
- func InitDatabase(forceRebuild bool)
- func InitHistoryDatabase(forceRebuild bool)
- func IsReusableTemplateKey(attrView *av.AttributeView, key *av.Key) bool
- func MoveTreeQueue(tree *parse.Tree)
- func NodeStaticContent(node *ast.Node, excludeTypes []string, ...) string
- func NodeStaticContentWithoutOCRAssets(node *ast.Node, excludeTypes []string, ...) string
- func OpenEncryptedDB(boxID string, dek []byte) (err error)
- func Query(stmt string, limit int) (ret []map[string]any, err error)
- func QueryAssetContentNoLimit(stmt string) (ret []map[string]any, err error)
- func QueryAssetContentNoLimitArgs(stmt string, args ...any) (ret []map[string]any, err error)
- func QueryAttributeViewRefDefIDsByBlockIDsInBox(blockIDs []string, boxID string) (ret []string)
- func QueryBacklinkRefDefsInBox(blockIDs []string, boxID string) (ret map[string][]string, err error)
- func QueryBlockAliasesInBox(rootID, boxID string) (ret []string)
- func QueryBlockDefIDsByRefTextInBox(refText, boxID string, accessible func(string, string) bool) (ret []string)
- func QueryBlockNamesByRootIDInBox(rootID, boxID string) (ret []string)
- func QueryBookmarkLabels() (ret []string)
- func QueryBoundBlockAVIDs(blockIDs, rootIDs []string) (ret map[string][]string, err error)
- func QueryBoundBlockAVIDsInBox(blockIDs, rootIDs []string, boxID string) (ret map[string][]string, err error)
- func QueryChildDefIDsByRootDefID(rootDefID string) (ret []string)
- func QueryChildDefIDsByRootDefIDInBox(rootDefID, boxID string) (ret []string)
- func QueryChildRefDefIDsByRootDefIDInBox(rootDefID, boxID string) (ret map[string][]string)
- func QueryDailyNoteRootIDsInBox(boxID, name, date string) (ids []string, err error)
- func QueryDocTreeRefCounts(ids, boxes []string, visible func(string, string) bool) (map[string]int, error)
- func QueryExactDocTitleIDInBox(title, id, rootID, boxID string) (ret string, err error)
- func QueryHistory(stmt string) (ret []map[string]any, err error)
- func QueryImageSpanMarkdowns() (ret []string, err error)
- func QueryNoLimit(stmt string) (ret []map[string]any, err error)
- func QueryNoLimitArgs(stmt string, args ...any) (ret []map[string]any, err error)
- func QueryNoLimitArgsInBox(stmt, boxID string, args ...any) (ret []map[string]any, err error)
- func QueryNoLimitArgsInBoxContext(ctx context.Context, stmt, boxID string, args ...any) (ret []map[string]any, err error)
- func QueryNoLimitInBox(stmt, boxID string) (ret []map[string]any, err error)
- func QueryNoLimitInBoxContext(ctx context.Context, stmt, boxID string) (ret []map[string]any, err error)
- func QueryRefCountInBox(defIDs []string, boxID string) (ret map[string]int)
- func QueryRefCountInBoxContext(ctx context.Context, defIDs []string, boxID string) (ret map[string]int)
- func QueryRefIDsByAnnotationID(annotationID string) (refIDs []string)
- func QueryRefIDsByAnnotationIDInBox(annotationID, boxID string) (refIDs []string)
- func QueryRefIDsByDefID(defID string, containChildren bool) (refIDs []string)
- func QueryRefIDsByDefIDInBox(defID string, containChildren bool, boxID string) (refIDs []string)
- func QueryRefRootBlocksByDefRootIDs(defRootIDs []string) (ret map[string][]*Block)
- func QueryRootBlockRefCount() (ret map[string]int)
- func QueryRootChildrenRefCountInBox(defRootID, boxID string) (ret map[string]int)
- func QueryTagCounts() (map[string]int, error)
- func QueryVirtualRefKeywords(name, alias, anchor, doc bool, ...) (ret []string)
- func ReadTagAssociations(withDates bool, consume func(label, attrs, box, path string, count int)) error
- func RebuildFTSIndex() (err error)
- func RefreshDefinitionRefsQueue(boxID string, ids []string)
- func RefreshHPathsBatch(doc *treenode.BlockTree, blockAfter, treeAfter int64, limit int) (nextBlock, nextTree int64, done, busy bool, err error)
- func RemapTemplateFieldIDs(source string, ids map[string]string) string
- func RemoveAllEncryptedDBFiles()
- func RemoveEncryptedDBFile(boxID string)
- func RemoveTreePathQueue(treeBox, treePathPrefix string)
- func RemoveTreeQueue(boxID, rootID string)
- func RenameDocQueue(tree *parse.Tree)
- func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string, depth *int, ...) (ret *av.Table)
- func RenderGroupView(attrView *av.AttributeView, view, groupView *av.View, query string) (ret av.Viewable)
- func RenderGroupViewWithSource(attrView *av.AttributeView, view, groupView *av.View, query string, ...) (ret av.Viewable)
- func RenderGroupViewWithSourceContext(attrView *av.AttributeView, view, groupView *av.View, query string, ...) (ret av.Viewable)
- func RenderView(attrView *av.AttributeView, view *av.View, query string, ignoreRows bool) (ret av.Viewable)
- func RenderViewGroupItems(attrView *av.AttributeView, view *av.View) []av.Item
- func RenderViewItem(attrView *av.AttributeView, view *av.View, itemID string) av.Viewable
- func RenderViewItemWithContext(attrView *av.AttributeView, view *av.View, itemID string, ...) av.Viewable
- func RenderViewWithContext(attrView *av.AttributeView, view *av.View, query string, ignoreRows bool, ...) (ret av.Viewable)
- func RenderViewWithDeferredTemplatesContext(attrView *av.AttributeView, view *av.View, query string, ignoreRows bool, ...) (ret av.Viewable)
- func SQLTemplateFuncs(templateFuncMap *template.FuncMap, boxIDs ...string)
- func SetCaseSensitive(b bool)
- func SetHanSensitive(b bool)
- func SetIndexAssetPath(b bool)
- func StaticTemplateKeyDependencies(attrView *av.AttributeView, key *av.Key) ([]*av.Key, bool)
- func TreeHasRefs(tree *parse.Tree) bool
- func UpdateBlockContentQueue(block *Block)
- func UpdateRefsTreeQueue(tree *parse.Tree)
- func UpsertTreeQueue(tree *parse.Tree)
- func UpsertTreeQueueWithChanges(tree *parse.Tree, changes *TreeIndexChanges)
- func Vacuum()
- func WaitFlushTx()
- type Asset
- type AssetContent
- type Attribute
- type AttributeViewRenderContext
- type Block
- func BuildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block)
- func GetAllChildBlocks(rootIDs []string, condition string, limit int) (ret []*Block)
- func GetAllRootBlocks() (ret []*Block)
- func GetBlock(id string) (ret *Block)
- func GetBlockInBox(id, boxID string) (ret *Block)
- func GetBlocks(ids []string) (ret []*Block)
- func GetBlocksInBox(ids []string, boxID string) (ret []*Block)
- func GetBlocksInBoxContext(ctx context.Context, ids []string, boxID string) (ret []*Block)
- func GetChildBlocks(parentID, condition string, limit int) (ret []*Block)
- func GetChildBlocksInBox(parentID, condition string, limit int, boxID string) (ret []*Block)
- func QueryBookmarkBlocks() (ret []*Block)
- func QueryDefRootBlocksByRefRootID(refRootID string) (ret []*Block)
- func QueryEmptyContentEmbedBlocks() (ret []*Block)
- func QueryEmptyContentEmbedBlocksInBox(boxID string) (ret []*Block)
- func QueryRootBlockByCondition(condition, exactKeyword string, limit int, args ...any) (ret []*Block)
- func QueryRootBlockByConditionInBox(condition, exactKeyword string, limit int, boxID string, args ...any) (ret []*Block)
- func SelectBlocksRawStmt(stmt string, page, limit int) (ret []*Block)
- func SelectBlocksRawStmtArgs(stmt string, args []any, limit int) (ret []*Block)
- func SelectBlocksRawStmtArgsInBox(stmt string, args []any, limit int, boxID string) (ret []*Block)
- func SelectBlocksRawStmtArgsInBoxContext(ctx context.Context, stmt string, args []any, limit int, boxID string) (ret []*Block, err error)
- func SelectBlocksRawStmtBoundedInBoxContext(ctx context.Context, stmt string, limit int, boxID string) (ret []*Block, truncated bool, err error)
- func SelectBlocksRawStmtInBox(stmt string, page, limit int, boxID string) (ret []*Block)
- func SelectBlocksRawStmtInBoxContext(ctx context.Context, stmt string, page, limit int, boxID string) (ret []*Block, err error)
- func SelectBlocksRawStmtNoParse(stmt string, limit int) (ret []*Block)
- func SelectBlocksRawStmtNoParseInBox(stmt string, limit int, boxID string) (ret []*Block)
- func SelectBlocksRegexArgsInBoxContext(ctx context.Context, stmt string, exp *regexp.Regexp, ...) (ret []*Block, err error)
- func SelectBlocksRegexInBox(stmt string, exp *regexp.Regexp, name, alias, memo, ial bool, ...) (ret []*Block)
- func SelectFTSBlocksWithCountContext(ctx context.Context, statement, countStatement string, args []any) (blocks []*Block, matches, docs int, err error)
- func ToBlocks(result []map[string]any) (ret []*Block)
- type BookmarkLabelBlock
- type FileAnnotationRef
- type GroupViewRenderSource
- type HTTPTemplatePreview
- type History
- type QueryLimitInfo
- type Ref
- func GetRefsCacheByDefID(defID string) (ret []*Ref)
- func GetRefsCacheByDefIDInBox(defID, boxID string) (ret []*Ref)
- func QueryRefsByDefID(defBlockID string, containChildren bool) (ret []*Ref)
- func QueryRefsByDefIDInBox(defBlockID string, containChildren bool, boxID string) (ret []*Ref)
- func QueryRefsByDefIDRefIDInBox(defBlockID, refBlockID, boxID string) (ret []*Ref)
- func QueryRefsByDefIDsInBox(defBlockIDs []string, boxID string) (ret []*Ref)
- func QueryRefsRecentInBox(onlyDoc bool, typeFilter string, ignoreLines, recentDefBlockIDs []string, ...) (ret []*Ref)
- type Span
- func QueryTagSpans(p string) (ret []*Span)
- func QueryTagSpansByKeyword(keyword string, limit int) (ret []*Span)
- func QueryTagSpansByLabel(label string) (ret []*Span)
- func SelectSpansRawStmt(stmt string, limit int) (ret []*Span)
- func SelectSpansRawStmtInBox(stmt string, limit int, boxID string) (ret []*Span)
- type Stat
- type TreeIndexChanges
Constants ¶
const ( AssetContentsFTSCaseInsensitiveInsert = "INSERT INTO asset_contents_fts_case_insensitive (id, name, ext, path, size, updated, content) VALUES %s" AssetContentsPlaceholder = "(?, ?, ?, ?, ?, ?, ?)" )
const ( HistoriesFTSCaseInsensitiveInsert = "INSERT INTO histories_fts_case_insensitive (id, type, op, title, content, path, created) VALUES %s" HistoriesPlaceholder = "(?, ?, ?, ?, ?, ?, ?)" )
const ( BlocksInsert = "" /* 182-byte string literal not displayed */ BlocksPlaceholder = "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" // blocks_fts 采用 external content 模式(content='blocks'),写入时必须显式提供 rowid, // 该 rowid 取自 blocks 表的隐式 rowid,否则 FTS rowid 与 blocks rowid 脱钩会导致 // snippet/highlight 回表取错行、按 rowid 删除静默失效。首列即为 rowid。 BlocksFTSInsert = "" /* 193-byte string literal not displayed */ BlocksFTSPlaceholder = "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" SpansInsert = "INSERT INTO spans (id, block_id, root_id, box, path, content, markdown, type, ial) VALUES %s" SpansPlaceholder = "(?, ?, ?, ?, ?, ?, ?, ?, ?)" AssetsPlaceholder = "(?, ?, ?, ?, ?, ?, ?, ?, ?)" AttributesPlaceholder = "(?, ?, ?, ?, ?, ?, ?, ?)" RefsPlaceholder = "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" FileAnnotationRefsPlaceholder = "(?, ?, ?, ?, ?, ?, ?, ?, ?)" )
const AttributeViewRefType = "av"
const BlockSearchMetadataPredicate = "(name != '' OR alias != '' OR memo != '' OR tag != '')"
字段拼接匹配需要补查元数据非空的块,部分索引使普通正文块不参与这一步扫描。
Variables ¶
var ( // IsEncryptedBoxFn 由 model 层注入,用于判断 boxID 是否为加密笔记本。 // sql 包不直接 import model(循环依赖),路由函数据此 fail-closed: // 加密笔记本未解锁时绝不回退全局库,避免加密笔记本索引污染全局明文库。 IsEncryptedBoxFn func(boxID string) bool // IsBoxUnlockedFn 由 model 层注入,用于在读取明文缓存前确认加密笔记本仍处于解锁状态。 IsBoxUnlockedFn func(boxID string) bool )
var ( // HPathRefreshLock 在重建索引前阻止路径任务写回;锁顺序为路径任务锁、数据库初始化锁、索引队列锁。 HPathRefreshLock sync.Mutex // ResetHPathRefreshQueue 由模型层注入,在持有 HPathRefreshLock 时同步清理普通索引的路径恢复记录。 ResetHPathRefreshQueue func() error )
var (
IndexIgnoreCached bool
)
Functions ¶
func BatchRemoveAssetsQueue ¶
func BatchRemoveAssetsQueue(hashes []string)
func BatchRemoveTreeQueue ¶
func BatchRemoveTreeQueue(rootIDs []string)
func CalculateEmbedBlockContent ¶
CalculateEmbedBlockContent 计算只读 SQL 嵌入的搜索内容;空脚本和 JavaScript 嵌入由前端更新。
func CheckAssetContentReadonlyStatement ¶
CheckAssetContentReadonlyStatement 在资源文件内容数据库连接上检查 SQL 是否只读。
func CheckHistoryReadonlyStatement ¶
CheckHistoryReadonlyStatement 在历史数据库连接上检查 SQL 为「单条 + 只读」。 历史查询语句只引用 history.db 中的表,必须在该连接上 prepare 才能通过校验。 见 https://github.com/siyuan-note/siyuan/security/advisories/GHSA-4hjx-84f6-gr7c
func CheckReadonlyBlockQueryStatement ¶
CheckReadonlyBlockQueryStatement 校验原始块查询语句为「单条 + 只读」,boxID 为空或普通笔记本时 在全局库上校验,加密笔记本在其独立加密库上校验。
嵌入块脚本、模板查询和导出路径的 SQL 都来自文档内容,属于不可信输入,执行前必须经过本校验。 见 https://github.com/siyuan-note/siyuan/security/advisories/GHSA-67p9-hm94-xwf3
func CheckReadonlyStatement ¶
CheckReadonlyStatement 对整段 SQL 做 prepare(不执行),用 sqlite3_stmt_readonly 判断首条语句是否只读。 见 https://sqlite.org/c3ref/stmt_readonly.html
注意:若字符串里在语法上还有第二条及以后的语句,本函数只针对「首条」对应的 stmt 做判断, 不会拒绝多语句。与 CheckSingleStatement 组合即可得到「单条 + 只读」策略。 仅允许 SELECT 和 WITH 查询,避免 SQLite 将 ATTACH、DETACH 和事务控制语句标记为只读后放行。
func CheckReadonlyStatementInBox ¶
CheckReadonlyStatementInBox 在指定笔记本对应的数据库连接上检查 SQL 是否只读。
func CheckSingleStatement ¶
func ClearCache ¶
func ClearCache()
func ClearQueue ¶
func ClearQueue()
func CloseDatabase ¶
func CloseDatabase()
func CloseEncryptedDB ¶
func CloseEncryptedDB(boxID string)
CloseEncryptedDB 仅关闭加密笔记本的 db 连接(不删文件)。UnlockBox 创建失败回滚时调用。 关闭/锁定加密笔记本请用 RemoveEncryptedDBFile(关连接 + 删文件)。
func DeleteAssetContentsByPathQueue ¶
func DeleteAssetContentsByPathQueue(path string)
func DeleteBoxQueue ¶
func DeleteBoxQueue(boxID string)
func DeleteBoxRefsQueue ¶
func DeleteBoxRefsQueue(boxID string)
func DeleteOutdatedHistories ¶
func DeleteOutdatedHistories(before int64)
func DeleteRefsTreeQueue ¶
func ExistRefByDefIDs ¶
func ExistRefByDefIDs(defIDs, defRootIDs, excludeBlockIDs, excludeRootIDs []string) (ret bool, err error)
ExistRefByDefIDs 检查全局库及所有已打开加密库中来自删除集合外部的引用。
func ExistRefByDefIDsInBox ¶
func ExistRefByDefIDsInBox(defIDs, defRootIDs, excludeBlockIDs, excludeRootIDs []string, boxID string) (ret bool, err error)
ExistRefByDefIDsInBox 检查指定笔记本索引中是否存在来自删除集合外部的引用。
func FillAttributeViewTemplateValuesForKeysWithContext ¶
func FillAttributeViewTemplateValuesForKeysWithContext(attrView *av.AttributeView, view *av.View, collection av.Collection, keys map[string]bool, renderContext *AttributeViewRenderContext)
FillAttributeViewTemplateValuesForKeysWithContext 只求值指定字段,保留其他字段已计算的显示结果。 keys 为 nil 时求值全部模板,非 nil 的空集合不执行模板。
func FillAttributeViewTemplateValuesWithContext ¶
func FillAttributeViewTemplateValuesWithContext(attrView *av.AttributeView, view *av.View, collection av.Collection, renderContext *AttributeViewRenderContext)
FillAttributeViewTemplateValuesWithContext 计算集合中当前条目的模板字段值和显示模板结果。
func FilterNonEmptyRefCheckIDs ¶
FilterNonEmptyRefCheckIDs 去空格、去空串并去重,保留首次出现的顺序。 供引用校验的多个入参列表共用,避免调用方各自实现一份。
func FilterVirtualRefKeywordsByAccess ¶
func FilterVirtualRefKeywordsByAccess(keywords []string, boxID string, accessible func(string, string) bool) (ret []string)
FilterVirtualRefKeywordsByAccess 批量校验文档中的候选关键字,避免逐个扫描引用与块索引。
func FlushAssetContentQueue ¶
func FlushAssetContentQueue() error
func FlushAssetContentTxJob ¶
func FlushAssetContentTxJob()
func FlushHistoryQueue ¶
func FlushHistoryQueue()
func FlushHistoryTxJob ¶
func FlushHistoryTxJob()
func FlushQueue ¶
func FlushQueue()
func FlushTxJob ¶
func FlushTxJob()
func GetBlockAttrs ¶
func GetContainerText ¶
func GetDuplicatedRootIDs ¶
func GetEncryptedBoxIDs ¶
func GetEncryptedBoxIDs() (ret []string)
GetEncryptedBoxIDs 返回所有已打开的加密 content db 对应的 boxID。
func GetEncryptedDB ¶
GetEncryptedDB 返回加密笔记本的 db 句柄;未打开返回 nil。
func GetFurtherCollections ¶
func GetFurtherCollections(attrView *av.AttributeView, cachedAttrViews map[string]*av.AttributeView) map[string]*av.RollupRenderContext
func GetFurtherCollectionsWithContext ¶
func GetFurtherCollectionsWithContext(attrView *av.AttributeView, cachedAttrViews map[string]*av.AttributeView, renderContext *AttributeViewRenderContext) map[string]*av.RollupRenderContext
GetFurtherCollectionsWithContext 使用指定的渲染上下文获取后续集合。
func GetRefDuplicatedDefRootIDs ¶
func GetRefDuplicatedDefRootIDs() (ret []string)
func GetRefText ¶
func GetRootUpdated ¶
func GetTemplateKeysByResolutionOrder ¶
func GetTemplateKeysByResolutionOrder(attrView *av.AttributeView) (ret []*av.Key, resolved bool)
func HasDocumentRefsOutsideRootsInBox ¶
func HasDocumentRefsOutsideRootsInBox(rootID string, owned map[string]bool, boxID string) (bool, error)
HasDocumentRefsOutsideRootsInBox 为新建后失败的保守清理保留任何外部引用;查询错误不能当作无引用。
func IndexAssetContentsQueue ¶
func IndexAssetContentsQueue(assetContents []*AssetContent)
func IndexHistoriesQueue ¶
func IndexHistoriesQueue(histories []*History)
func IndexNodeQueue ¶
func IndexNodeQueue(id string)
func IndexRecoveryPending ¶
func IndexRecoveryPending() bool
IndexRecoveryPending 供同步应用准入检查,涵盖正在处理和等待处理的历史记录。
func IndexTreeQueue ¶
func InitDatabase ¶
func InitDatabase(forceRebuild bool)
func InitHistoryDatabase ¶
func InitHistoryDatabase(forceRebuild bool)
func IsReusableTemplateKey ¶
func IsReusableTemplateKey(attrView *av.AttributeView, key *av.Key) bool
IsReusableTemplateKey 仅接纳封闭的字段访问和字符串格式化,不依赖时间、SQL 或外部状态。
func MoveTreeQueue ¶
func NodeStaticContent ¶
func NodeStaticContentWithoutOCRAssets ¶
func NodeStaticContentWithoutOCRAssets(node *ast.Node, excludeTypes []string, includeTextMarkATitleURL, includeAssetPath, fullAttrView bool) string
NodeStaticContentWithoutOCRAssets 与 NodeStaticContent 相同,但不读取资源的 OCR 文本。
func OpenEncryptedDB ¶
OpenEncryptedDB 打开加密笔记本的独立 SQLCipher db 并注册到 encryptedDBs。 dek 是该 box 的 32 字节数据密钥;先用 HKDF 派生 content 子密钥(用途分离),DSN 用 raw key 格式 x'<hex>'。 首次打开会建表(幂等 IF NOT EXISTS)。UnlockBox 时调用。
func QueryAssetContentNoLimitArgs ¶
QueryAssetContentNoLimitArgs 使用绑定参数查询资源文件内容数据库。
func QueryAttributeViewRefDefIDsByBlockIDsInBox ¶
QueryAttributeViewRefDefIDsByBlockIDsInBox 按数据库载体块查询属性视图引用的定义块 ID。
func QueryBacklinkRefDefsInBox ¶
func QueryBacklinkRefDefsInBox(blockIDs []string, boxID string) (ret map[string][]string, err error)
QueryBacklinkRefDefsInBox 批量读取条目内容块的引用关系,保留数据库隔离边界。
func QueryBlockAliasesInBox ¶
QueryBlockAliasesInBox 按 rootID 在指定 box 的 db 里查块别名(按逗号拆分去重)。
func QueryBlockNamesByRootIDInBox ¶
QueryBlockNamesByRootIDInBox 按 rootID 在指定 box 的 db 里查块命名。
func QueryBookmarkLabels ¶
func QueryBookmarkLabels() (ret []string)
func QueryBoundBlockAVIDs ¶
QueryBoundBlockAVIDs 查询全局库及所有已打开加密库中删除集合内的数据库绑定块。
func QueryBoundBlockAVIDsInBox ¶
func QueryBoundBlockAVIDsInBox(blockIDs, rootIDs []string, boxID string) (ret map[string][]string, err error)
QueryBoundBlockAVIDsInBox 查询删除集合中绑定块所属的属性视图。
func QueryChildDefIDsByRootDefIDInBox ¶
QueryChildDefIDsByRootDefIDInBox 按定义文档根 ID 查询存在引用的子定义块,按 boxID 路由。
func QueryChildRefDefIDsByRootDefIDInBox ¶
QueryChildRefDefIDsByRootDefIDInBox 按 rootDefID 查子引用定义,按 boxID 路由。
func QueryDailyNoteRootIDsInBox ¶
QueryDailyNoteRootIDsInBox 按日记属性查询文档,限定笔记本并保留数据库错误。
func QueryDocTreeRefCounts ¶
func QueryDocTreeRefCounts(ids, boxes []string, visible func(string, string) bool) (map[string]int, error)
QueryDocTreeRefCounts 只查询所需根文档;ids 为 nil 时用于引用数排序的首次构建。 boxes 由调用方已持有的笔记本租约确定,空字符串表示普通数据库。
func QueryExactDocTitleIDInBox ¶
QueryExactDocTitleIDInBox 按完整文档标题查询,先精确匹配,再匹配 Unicode 大小写,保留数据库错误。
func QueryImageSpanMarkdowns ¶
QueryImageSpanMarkdowns 读取全局索引中的图片引用,保留同一段落内各图片的元数据归属。
func QueryNoLimitArgs ¶
QueryNoLimitArgs 与 QueryNoLimit 一致,但支持参数化查询(stmt 中用 ? 占位,args 顺序填入)。 用于 embedding 索引器按 fail_count/last_tried 调度时的带参 SELECT。
func QueryNoLimitArgsInBox ¶
QueryNoLimitArgsInBox 与 QueryNoLimitInBox 一致,但支持参数化查询。
func QueryNoLimitArgsInBoxContext ¶
func QueryNoLimitArgsInBoxContext(ctx context.Context, stmt, boxID string, args ...any) (ret []map[string]any, err error)
QueryNoLimitArgsInBoxContext 在请求取消时中断参数化查询,并保留笔记本数据库路由。
func QueryNoLimitInBox ¶
QueryNoLimitInBox 在指定 box 的 db 里执行无 limit 的原始查询(返回 map 行)。
func QueryRefCountInBox ¶
QueryRefCountInBox 按 defBlockIDs 在指定 box 的 db 里查引用计数。
func QueryRefCountInBoxContext ¶
func QueryRefCountInBoxContext(ctx context.Context, defIDs []string, boxID string) (ret map[string]int)
QueryRefCountInBoxContext 在搜索取消后停止引用计数,沿用原有的笔记本隔离。
func QueryRefIDsByDefID ¶
func QueryRefIDsByDefIDInBox ¶
QueryRefIDsByDefIDInBox 按 defID 查引用 ID 列表,按 boxID 路由。
func QueryRootBlockRefCount ¶
func QueryRootChildrenRefCountInBox ¶
QueryRootChildrenRefCountInBox 按 defRootID 在指定 box 的 db 里查询根文档下各块的引用计数。
func QueryTagCounts ¶
func QueryVirtualRefKeywords ¶
func ReadTagAssociations ¶
func RebuildFTSIndex ¶
func RebuildFTSIndex() (err error)
func RefreshDefinitionRefsQueue ¶
RefreshDefinitionRefsQueue follows the committed source/target indexing operations. Recovery needs only stable IDs, never the reference source files.
func RefreshHPathsBatch ¶
func RefreshHPathsBatch(doc *treenode.BlockTree, blockAfter, treeAfter int64, limit int) (nextBlock, nextTree int64, done, busy bool, err error)
RefreshHPathsBatch 只在普通索引空闲时执行一个批次,不占用普通任务队列等待下一批。
func RemapTemplateFieldIDs ¶
RemapTemplateFieldIDs 仅替换可静态识别的字段身份查找,不替换普通文字或变量声明。 使用独立解析树的字节位置编辑原文;无效模板及动态构造的字段身份保持原样。
func RemoveAllEncryptedDBFiles ¶
func RemoveAllEncryptedDBFiles()
RemoveAllEncryptedDBFiles 关闭所有已打开的加密 content db 连接并删除其文件(含 WAL/SHM)。 进程退出(CloseDatabase)时调用,避免重启后残留旧索引数据导致下次解锁叠加重复行。
func RemoveEncryptedDBFile ¶
func RemoveEncryptedDBFile(boxID string)
RemoveEncryptedDBFile 关闭连接并删除加密 db 文件(含 WAL/SHM)。删除笔记本、关闭加密笔记本时调用。
func RemoveTreePathQueue ¶
func RemoveTreePathQueue(treeBox, treePathPrefix string)
func RemoveTreeQueue ¶
func RemoveTreeQueue(boxID, rootID string)
func RenameDocQueue ¶
RenameDocQueue 及时更新文档标题,内容块的路径副本由独立后台任务补齐。
func RenderGroupView ¶
func RenderGroupViewWithSource ¶
func RenderGroupViewWithSource(attrView *av.AttributeView, view, groupView *av.View, query string, source *GroupViewRenderSource, ignoreRows bool) (ret av.Viewable)
RenderGroupViewWithSource 优先从父视图条目索引组装分组;布局或查询不匹配时沿用独立渲染。
func RenderGroupViewWithSourceContext ¶
func RenderGroupViewWithSourceContext(attrView *av.AttributeView, view, groupView *av.View, query string, source *GroupViewRenderSource, ignoreRows bool, context *AttributeViewRenderContext) (ret av.Viewable)
RenderGroupViewWithSourceContext 使用指定的渲染上下文渲染分组视图。
func RenderView ¶
func RenderViewGroupItems ¶
func RenderViewItem ¶
RenderViewItem 为属性面板计算单条记录,关联汇总仅物化该记录依赖的条目。
func RenderViewItemWithContext ¶
func RenderViewItemWithContext(attrView *av.AttributeView, view *av.View, itemID string, context *AttributeViewRenderContext) av.Viewable
单条元数据读取可显式禁止派生值持久化,且保留数据库已固定的依赖读取边界。
func RenderViewWithContext ¶
func RenderViewWithContext(attrView *av.AttributeView, view *av.View, query string, ignoreRows bool, renderContext *AttributeViewRenderContext) (ret av.Viewable)
RenderViewWithContext 使用指定的渲染上下文渲染属性视图。
func RenderViewWithDeferredTemplatesContext ¶
func RenderViewWithDeferredTemplatesContext(attrView *av.AttributeView, view *av.View, query string, ignoreRows bool, renderContext *AttributeViewRenderContext) (ret av.Viewable)
RenderViewWithDeferredTemplatesContext 生成尚未计算模板字段的普通视图。
func SQLTemplateFuncs ¶
func SetCaseSensitive ¶
func SetCaseSensitive(b bool)
func SetHanSensitive ¶
func SetHanSensitive(b bool)
func SetIndexAssetPath ¶
func SetIndexAssetPath(b bool)
func StaticTemplateKeyDependencies ¶
StaticTemplateKeyDependencies 复用字段依赖解析,仅为可静态识别的表达式返回完整依赖。 分支、命名模板、变量别名或动态访问保留完整求值路径,避免将遗漏依赖当成显示字段。
func TreeHasRefs ¶
TreeHasRefs uses the same extraction as normal indexing, including rich inline titles, attribute views and embedded references.
func UpdateBlockContentQueue ¶
func UpdateBlockContentQueue(block *Block)
func UpdateRefsTreeQueue ¶
func UpsertTreeQueue ¶
func UpsertTreeQueueWithChanges ¶
func UpsertTreeQueueWithChanges(tree *parse.Tree, changes *TreeIndexChanges)
UpsertTreeQueueWithChanges 合并同一文档的影响集合;未知影响范围或有序操作边界保留完整更新。
func WaitFlushTx ¶
func WaitFlushTx()
Types ¶
type Asset ¶
type Asset struct {
ID string
BlockID string
RootID string
Box string
DocPath string
Path string
Name string
Title string
Hash string
}
func QueryAssetByHash ¶
type AssetContent ¶
type AssetContent struct {
ID string
Name string
Ext string
Path string
Size int64
Updated int64
Content string
}
func SelectAssetContentsRawStmt ¶
func SelectAssetContentsRawStmt(stmt string, page, limit int) (ret []*AssetContent)
func SelectAssetContentsRawStmtNoParse ¶
func SelectAssetContentsRawStmtNoParse(stmt string, limit int) (ret []*AssetContent)
func SelectAssetContentsRawStmtNoParseArgs ¶
func SelectAssetContentsRawStmtNoParseArgs(stmt string, args []any, limit int) (ret []*AssetContent)
SelectAssetContentsRawStmtNoParseArgs 使用绑定参数查询资源文件内容,并保留调用方构造的 SQL。
type AttributeViewRenderContext ¶
type AttributeViewRenderContext struct {
HTTPPreview *HTTPTemplatePreview
TemplateHTTP *templatehttp.Execution
TemplateHTTPSourceScope func(owner, avID, keyID, slot, content string) string
ReadOnly bool // 预览只允许修正内存副本,不保存缺失字段等订正结果。
HistoricalAttributeViewID string // 已认证历史源的条目及块属性取自源数据,不使用实时块索引裁剪。
// contains filtered or unexported fields
}
AttributeViewRenderContext 收集一次属性视图渲染期间产生的模板错误。
func NewAttributeViewRenderContext ¶
func NewAttributeViewRenderContext() *AttributeViewRenderContext
NewAttributeViewRenderContext 创建属性视图渲染上下文。
func (*AttributeViewRenderContext) HTTPTemplateError ¶
func (context *AttributeViewRenderContext) HTTPTemplateError() error
HTTPTemplateError 仅将取消、锁定和执行预算终止提升为整个渲染失败。
func (*AttributeViewRenderContext) HasTemplateErrors ¶
func (context *AttributeViewRenderContext) HasTemplateErrors() bool
HasTemplateErrors 判断本次求值是否产生模板错误,错误结果不参与跨请求复用。
func (*AttributeViewRenderContext) PushTemplateErrors ¶
func (context *AttributeViewRenderContext) PushTemplateErrors()
type Block ¶
type Block struct {
ID string
ParentID string
RootID string
Hash string
Box string
Path string
HPath string
Name string
Alias string
Memo string
Tag string
Content string
FContent string
Markdown string
Length int
Type string
SubType string
IAL string
Sort int
Created string
Updated string
}
func GetAllChildBlocks ¶
func GetAllRootBlocks ¶
func GetAllRootBlocks() (ret []*Block)
func GetBlockInBox ¶
GetBlockInBox 按 id 在指定 box 的 db 里查 block。boxID 为空则查全局 db。
func GetBlocksInBox ¶
GetBlocksInBox 按 ids 在指定 box 的 db 里批量查 block。
func GetBlocksInBoxContext ¶
GetBlocksInBoxContext 保留缓存、分批查询和输入顺序,并在请求取消后停止读取。
func GetChildBlocks ¶
func GetChildBlocksInBox ¶
GetChildBlocksInBox 按 parentID 在指定 box 的 db 里查所有子块。
func QueryBookmarkBlocks ¶
func QueryBookmarkBlocks() (ret []*Block)
func QueryEmptyContentEmbedBlocks ¶
func QueryEmptyContentEmbedBlocks() (ret []*Block)
func SelectBlocksRawStmt ¶
func SelectBlocksRawStmtArgs ¶
SelectBlocksRawStmtArgs 与 selectBlocksRawStmt 行为一致,但通过绑定参数执行, 绕开 sqlparser 解析(vitess 会把 "?" 改写为 ":vN" 导致占位失效),用于含用户可控参数的搜索语句。
func SelectBlocksRawStmtArgsInBox ¶
SelectBlocksRawStmtArgsInBox 在指定 box 的 db 里执行参数化原始 SQL 查询 blocks。 与 SelectBlocksRawStmtArgs 对应,绕开 sqlparser 对 "?" 占位的改写。
func SelectBlocksRawStmtArgsInBoxContext ¶
func SelectBlocksRawStmtArgsInBoxContext(ctx context.Context, stmt string, args []any, limit int, boxID string) (ret []*Block, err error)
SelectBlocksRawStmtArgsInBoxContext 取消参数化块查询,不将取消后的部分行作为完整结果返回。
func SelectBlocksRawStmtBoundedInBoxContext ¶
func SelectBlocksRawStmtBoundedInBoxContext(ctx context.Context, stmt string, limit int, boxID string) (ret []*Block, truncated bool, err error)
SelectBlocksRawStmtBoundedInBoxContext 执行原始块查询,并无条件限制返回行数。
func SelectBlocksRawStmtInBox ¶
SelectBlocksRawStmtInBox 在指定 box 的 db 里执行原始 SQL 查询 blocks。
func SelectBlocksRawStmtNoParseInBox ¶
SelectBlocksRawStmtNoParseInBox 与 SelectBlocksRawStmtNoParse 一致,但按 boxID 路由。
func SelectBlocksRegexArgsInBoxContext ¶
func SelectBlocksRegexArgsInBoxContext(ctx context.Context, stmt string, exp *regexp.Regexp, name, alias, memo, ial bool, page, pageSize int, boxID string, args ...any) (ret []*Block, err error)
SelectBlocksRegexArgsInBoxContext 同时中断数据库扫描和逐块正则高亮。
func SelectBlocksRegexInBox ¶
func SelectBlocksRegexInBox(stmt string, exp *regexp.Regexp, name, alias, memo, ial bool, page, pageSize int, boxID string) (ret []*Block)
SelectBlocksRegexInBox 在指定 box 的 db 里执行正则匹配查询 blocks(无占位参数版)。
func SelectFTSBlocksWithCountContext ¶
func SelectFTSBlocksWithCountContext(ctx context.Context, statement, countStatement string, args []any) (blocks []*Block, matches, docs int, err error)
SelectFTSBlocksWithCountContext 在同一普通库读取快照内取得分页行及精确计数。 仅供固定 FTS 查询使用;加密库、自定义 SQL 和动态忽略条件使用各自的既有路径。
func (*Block) IsContainerBlock ¶
type BookmarkLabelBlock ¶
func QueryBookmarkLabelBlocks ¶
func QueryBookmarkLabelBlocks() (ret []*BookmarkLabelBlock)
type FileAnnotationRef ¶
type GroupViewRenderSource ¶
type GroupViewRenderSource struct {
// contains filtered or unexported fields
}
GroupViewRenderSource 保存分组渲染可复用的条目索引。 索引中的条目已经完成字段值生成和查询过滤,各分组仍会独立执行视图过滤、排序、统计和分页。
func NewGroupViewRenderSource ¶
func NewGroupViewRenderSource(viewable av.Viewable, query string) (ret *GroupViewRenderSource)
NewGroupViewRenderSource 在父视图分页前建立可供所有同布局分组复用的条目索引。
func (*GroupViewRenderSource) GetItems ¶
func (source *GroupViewRenderSource) GetItems() (ret []av.Item)
GetItems 返回父视图分页前的完整有序条目列表。
type HTTPTemplatePreview ¶
type HTTPTemplatePreview struct {
// contains filtered or unexported fields
}
func (*HTTPTemplatePreview) Pending ¶
func (preview *HTTPTemplatePreview) Pending() []string
func (*HTTPTemplatePreview) Prepare ¶
func (preview *HTTPTemplatePreview) Prepare(database *av.AttributeView) bool
Prepare 同库模板共享求值顺序,首屏一并延后,避免下游模板读取未完成的联网结果。
type History ¶
type History struct {
ID string
Type int
Op string
Title string
Content string
Created string
Path string
}
func SelectHistoriesRawStmt ¶
type QueryLimitInfo ¶
QueryLimitInfo 描述查询行数限制;Limit 为零表示使用 SQL 自身的限制。
func QueryWithLimitInfo ¶
func QueryWithLimitInfo(stmt string, limit int) (rows []map[string]any, info QueryLimitInfo, err error)
QueryWithLimitInfo 在同一次查询中多读取一行,判断默认限制是否截断了结果。
func QueryWithRowLimitInfo ¶
func QueryWithRowLimitInfo(stmt string, limit int) (rows []map[string]any, info QueryLimitInfo, err error)
QueryWithRowLimitInfo 在 SQL 自身限制之外封顶返回行数,并多读取一行判断是否截断。 直接执行原始语句,保留注释、递归查询和解析器不支持的 SQLite 语法。
type Ref ¶
type Ref struct {
ID string
DefBlockID string
DefBlockParentID string
DefBlockRootID string
DefBlockPath string
BlockID string
RootID string
Box string
Path string
Content string
Markdown string
Type string
}
func GetRefsCacheByDefID ¶
func QueryRefsByDefID ¶
func QueryRefsByDefIDInBox ¶
QueryRefsByDefIDInBox 按 defBlockID 在指定 box 的 db 里查引用列表。 containChildren 为 true 时递归查询定义块及其所有子块,与 QueryRefsByDefID 保持一致。
func QueryRefsByDefIDRefIDInBox ¶
QueryRefsByDefIDRefIDInBox 按 defBlockID+refBlockID 在指定 box 的 db 里查引用。
func QueryRefsByDefIDsInBox ¶
QueryRefsByDefIDsInBox 按一组定义块 ID 查询引用,按 boxID 路由。
type Span ¶
type Span struct {
ID string
BlockID string
RootID string
Box string
Path string
Content string
Markdown string
Type string
IAL string
}
func QueryTagSpans ¶
func QueryTagSpansByKeyword ¶
func QueryTagSpansByLabel ¶
func SelectSpansRawStmt ¶
type TreeIndexChanges ¶
type TreeIndexChanges struct {
// contains filtered or unexported fields
}
TreeIndexChanges 是完整事务影响集合的进程内提示;nil 表示必须重新生成全部主块投影。 集合须包含变更、删除和替换子树的块以及受影响容器,入队时复制且不写入恢复队列。
func NewTreeIndexChanges ¶
func NewTreeIndexChanges(blockIDs []string) *TreeIndexChanges
Source Files
¶
- asset.go
- asset_content.go
- asset_content_query.go
- attribute.go
- attribute_view_ref.go
- auxiliary_index.go
- av.go
- av_gallery.go
- av_group.go
- av_http_preview.go
- av_item.go
- av_kanban.go
- av_relation_template.go
- av_rollup_target.go
- av_table.go
- av_template_identity.go
- av_template_inputs.go
- av_template_plan.go
- backlink_ref_defs.go
- block.go
- block_query.go
- block_ref.go
- block_ref_query.go
- cache.go
- database.go
- database_write.go
- delete_path.go
- doc_tree.go
- document_title.go
- embed_content.go
- encrypted_query.go
- file_annotation_ref.go
- history.go
- hpath.go
- index_changes.go
- index_projection.go
- index_queue.go
- ocr.go
- query_limit.go
- queue.go
- queue_asset_content.go
- queue_history.go
- relation_created_docs.go
- search_count_cache.go
- search_metadata_index.go
- span.go
- stat.go
- stmt_validate.go
- upsert.go