mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
🎨 改进索引订正,考虑大小写库
This commit is contained in:
parent
772984fe1b
commit
f84efb9efa
2 changed files with 51 additions and 31 deletions
|
|
@ -1307,8 +1307,45 @@ func autoFixIndex() {
|
|||
|
||||
// 对比块树和数据库并订正数据库
|
||||
rootUpdatedMap := treenode.GetRootUpdated()
|
||||
dbRootUpdatedMap, err := sql.GetRootUpdated()
|
||||
dbRootUpdatedMap, err := sql.GetRootUpdated("blocks")
|
||||
if nil == err {
|
||||
reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap)
|
||||
}
|
||||
dbFtsRootUpdatedMap, err := sql.GetRootUpdated("blocks_fts")
|
||||
if nil == err {
|
||||
reindexTreeByUpdated(rootUpdatedMap, dbFtsRootUpdatedMap)
|
||||
}
|
||||
if !Conf.Search.CaseSensitive {
|
||||
dbFtsRootUpdatedMap, err := sql.GetRootUpdated("blocks_fts_case_insensitive")
|
||||
if nil == err {
|
||||
reindexTreeByUpdated(rootUpdatedMap, dbFtsRootUpdatedMap)
|
||||
}
|
||||
}
|
||||
|
||||
// 去除重复的数据库块记录
|
||||
duplicatedRootIDs := sql.GetDuplicatedRootIDs("blocks")
|
||||
if 1 > len(duplicatedRootIDs) {
|
||||
duplicatedRootIDs = sql.GetDuplicatedRootIDs("blocks_fts")
|
||||
if 1 > len(duplicatedRootIDs) && !Conf.Search.CaseSensitive {
|
||||
duplicatedRootIDs = sql.GetDuplicatedRootIDs("blocks_fts_case_insensitive")
|
||||
}
|
||||
}
|
||||
size := len(duplicatedRootIDs)
|
||||
for i, rootID := range duplicatedRootIDs {
|
||||
root := sql.GetBlock(rootID)
|
||||
if nil == root {
|
||||
continue
|
||||
}
|
||||
|
||||
logging.LogWarnf("exist more than one tree [%s], reindex it", rootID)
|
||||
sql.RemoveTreeQueue(root.Box, rootID)
|
||||
reindexTree(rootID, i, size)
|
||||
}
|
||||
|
||||
util.PushStatusBar(Conf.Language(185))
|
||||
}
|
||||
|
||||
func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string) {
|
||||
i := -1
|
||||
size := len(rootUpdatedMap)
|
||||
for rootID, updated := range rootUpdatedMap {
|
||||
|
|
@ -1335,23 +1372,6 @@ func autoFixIndex() {
|
|||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 去除重复的数据库块记录
|
||||
duplicatedRootIDs := sql.GetDuplicatedRootIDs()
|
||||
size := len(duplicatedRootIDs)
|
||||
for i, rootID := range duplicatedRootIDs {
|
||||
root := sql.GetBlock(rootID)
|
||||
if nil == root {
|
||||
continue
|
||||
}
|
||||
|
||||
logging.LogWarnf("exist more than one tree [%s], reindex it", rootID)
|
||||
sql.RemoveTreeQueue(root.Box, rootID)
|
||||
reindexTree(rootID, i, size)
|
||||
}
|
||||
|
||||
util.PushStatusBar(Conf.Language(185))
|
||||
}
|
||||
|
||||
func reindexTreeByPath(box, p string, i, size int) {
|
||||
|
|
|
|||
|
|
@ -597,8 +597,8 @@ func GetBlock(id string) (ret *Block) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetRootUpdated() (ret map[string]string, err error) {
|
||||
rows, err := query("SELECT root_id, updated FROM blocks WHERE type = 'd'")
|
||||
func GetRootUpdated(blocksTable string) (ret map[string]string, err error) {
|
||||
rows, err := query("SELECT root_id, updated FROM `" + blocksTable + "` WHERE type = 'd'")
|
||||
if nil != err {
|
||||
logging.LogErrorf("sql query failed: %s", err)
|
||||
return
|
||||
|
|
@ -614,8 +614,8 @@ func GetRootUpdated() (ret map[string]string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetDuplicatedRootIDs() (ret []string) {
|
||||
rows, err := query("SELECT DISTINCT root_id FROM blocks GROUP BY id HAVING COUNT(*) > 1")
|
||||
func GetDuplicatedRootIDs(blocksTable string) (ret []string) {
|
||||
rows, err := query("SELECT DISTINCT root_id FROM `" + blocksTable + "` GROUP BY id HAVING COUNT(*) > 1")
|
||||
if nil != err {
|
||||
logging.LogErrorf("sql query failed: %s", err)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue