mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 07:30: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()
|
rootUpdatedMap := treenode.GetRootUpdated()
|
||||||
dbRootUpdatedMap, err := sql.GetRootUpdated()
|
dbRootUpdatedMap, err := sql.GetRootUpdated("blocks")
|
||||||
if nil == err {
|
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
|
i := -1
|
||||||
size := len(rootUpdatedMap)
|
size := len(rootUpdatedMap)
|
||||||
for rootID, updated := range rootUpdatedMap {
|
for rootID, updated := range rootUpdatedMap {
|
||||||
|
|
@ -1337,23 +1374,6 @@ func autoFixIndex() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 去除重复的数据库块记录
|
|
||||||
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) {
|
func reindexTreeByPath(box, p string, i, size int) {
|
||||||
tree, err := LoadTree(box, p)
|
tree, err := LoadTree(box, p)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
|
||||||
|
|
@ -597,8 +597,8 @@ func GetBlock(id string) (ret *Block) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRootUpdated() (ret map[string]string, err error) {
|
func GetRootUpdated(blocksTable string) (ret map[string]string, err error) {
|
||||||
rows, err := query("SELECT root_id, updated FROM blocks WHERE type = 'd'")
|
rows, err := query("SELECT root_id, updated FROM `" + blocksTable + "` WHERE type = 'd'")
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("sql query failed: %s", err)
|
logging.LogErrorf("sql query failed: %s", err)
|
||||||
return
|
return
|
||||||
|
|
@ -614,8 +614,8 @@ func GetRootUpdated() (ret map[string]string, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDuplicatedRootIDs() (ret []string) {
|
func GetDuplicatedRootIDs(blocksTable string) (ret []string) {
|
||||||
rows, err := query("SELECT DISTINCT root_id FROM blocks GROUP BY id HAVING COUNT(*) > 1")
|
rows, err := query("SELECT DISTINCT root_id FROM `" + blocksTable + "` GROUP BY id HAVING COUNT(*) > 1")
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("sql query failed: %s", err)
|
logging.LogErrorf("sql query failed: %s", err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue