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,38 +1307,29 @@ func autoFixIndex() {
|
||||||
|
|
||||||
// 对比块树和数据库并订正数据库
|
// 对比块树和数据库并订正数据库
|
||||||
rootUpdatedMap := treenode.GetRootUpdated()
|
rootUpdatedMap := treenode.GetRootUpdated()
|
||||||
dbRootUpdatedMap, err := sql.GetRootUpdated()
|
dbRootUpdatedMap, err := sql.GetRootUpdated("blocks")
|
||||||
if nil == err {
|
if nil == err {
|
||||||
i := -1
|
reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap)
|
||||||
size := len(rootUpdatedMap)
|
}
|
||||||
for rootID, updated := range rootUpdatedMap {
|
dbFtsRootUpdatedMap, err := sql.GetRootUpdated("blocks_fts")
|
||||||
i++
|
if nil == err {
|
||||||
|
reindexTreeByUpdated(rootUpdatedMap, dbFtsRootUpdatedMap)
|
||||||
rootUpdated := dbRootUpdatedMap[rootID]
|
}
|
||||||
if "" == rootUpdated {
|
if !Conf.Search.CaseSensitive {
|
||||||
logging.LogWarnf("not found tree [%s] in database, reindex it", rootID)
|
dbFtsRootUpdatedMap, err := sql.GetRootUpdated("blocks_fts_case_insensitive")
|
||||||
reindexTree(rootID, i, size)
|
if nil == err {
|
||||||
continue
|
reindexTreeByUpdated(rootUpdatedMap, dbFtsRootUpdatedMap)
|
||||||
}
|
|
||||||
|
|
||||||
if "" == updated {
|
|
||||||
// BlockTree 迁移,v2.6.3 之前没有 updated 字段
|
|
||||||
reindexTree(rootID, i, size)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
btUpdated, _ := time.Parse("20060102150405", updated)
|
|
||||||
dbUpdated, _ := time.Parse("20060102150405", rootUpdated)
|
|
||||||
if dbUpdated.Before(btUpdated.Add(-10 * time.Minute)) {
|
|
||||||
logging.LogWarnf("tree [%s] is not up to date, reindex it", rootID)
|
|
||||||
reindexTree(rootID, i, size)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 去除重复的数据库块记录
|
// 去除重复的数据库块记录
|
||||||
duplicatedRootIDs := sql.GetDuplicatedRootIDs()
|
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)
|
size := len(duplicatedRootIDs)
|
||||||
for i, rootID := range duplicatedRootIDs {
|
for i, rootID := range duplicatedRootIDs {
|
||||||
root := sql.GetBlock(rootID)
|
root := sql.GetBlock(rootID)
|
||||||
|
|
@ -1354,6 +1345,35 @@ func autoFixIndex() {
|
||||||
util.PushStatusBar(Conf.Language(185))
|
util.PushStatusBar(Conf.Language(185))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string) {
|
||||||
|
i := -1
|
||||||
|
size := len(rootUpdatedMap)
|
||||||
|
for rootID, updated := range rootUpdatedMap {
|
||||||
|
i++
|
||||||
|
|
||||||
|
rootUpdated := dbRootUpdatedMap[rootID]
|
||||||
|
if "" == rootUpdated {
|
||||||
|
logging.LogWarnf("not found tree [%s] in database, reindex it", rootID)
|
||||||
|
reindexTree(rootID, i, size)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if "" == updated {
|
||||||
|
// BlockTree 迁移,v2.6.3 之前没有 updated 字段
|
||||||
|
reindexTree(rootID, i, size)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
btUpdated, _ := time.Parse("20060102150405", updated)
|
||||||
|
dbUpdated, _ := time.Parse("20060102150405", rootUpdated)
|
||||||
|
if dbUpdated.Before(btUpdated.Add(-10 * time.Minute)) {
|
||||||
|
logging.LogWarnf("tree [%s] is not up to date, reindex it", rootID)
|
||||||
|
reindexTree(rootID, i, size)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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