mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 07:30:12 +01:00
This commit is contained in:
parent
c631b64d00
commit
dc112fd56c
2 changed files with 36 additions and 31 deletions
|
|
@ -1238,42 +1238,43 @@ func autoFixIndex() {
|
||||||
defer autoFixLock.Unlock()
|
defer autoFixLock.Unlock()
|
||||||
|
|
||||||
rootUpdatedMap := treenode.GetRootUpdated()
|
rootUpdatedMap := treenode.GetRootUpdated()
|
||||||
i := -1
|
dbRootUpdatedMap, err := sql.GetRootUpdated()
|
||||||
size := len(rootUpdatedMap)
|
if nil == err {
|
||||||
for rootID, updated := range rootUpdatedMap {
|
i := -1
|
||||||
if isFullReindexing {
|
size := len(rootUpdatedMap)
|
||||||
break
|
for rootID, updated := range rootUpdatedMap {
|
||||||
}
|
if isFullReindexing {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
i++
|
i++
|
||||||
|
|
||||||
rootUpdated, err := sql.GetRootUpdated(rootID)
|
rootUpdated := dbRootUpdatedMap[rootID]
|
||||||
if nil != err {
|
if "" == rootUpdated {
|
||||||
continue
|
logging.LogWarnf("not found tree [%s] in database, reindex it", rootID)
|
||||||
}
|
reindexTree(rootID, i, size)
|
||||||
if "" == rootUpdated {
|
continue
|
||||||
logging.LogWarnf("not found tree [%s] in database, reindex it", rootID)
|
}
|
||||||
reindexTree(rootID, i, size)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if "" == updated {
|
if "" == updated {
|
||||||
// BlockTree 迁移,v2.6.3 之前没有 updated 字段
|
// BlockTree 迁移,v2.6.3 之前没有 updated 字段
|
||||||
reindexTree(rootID, i, size)
|
reindexTree(rootID, i, size)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
btUpdated, _ := time.Parse("20060102150405", updated)
|
btUpdated, _ := time.Parse("20060102150405", updated)
|
||||||
dbUpdated, _ := time.Parse("20060102150405", rootUpdated)
|
dbUpdated, _ := time.Parse("20060102150405", rootUpdated)
|
||||||
if dbUpdated.Before(btUpdated.Add(-1 * time.Minute)) {
|
if dbUpdated.Before(btUpdated.Add(-1 * time.Minute)) {
|
||||||
logging.LogWarnf("tree [%s] is not up to date, reindex it", rootID)
|
logging.LogWarnf("tree [%s] is not up to date, reindex it", rootID)
|
||||||
reindexTree(rootID, i, size)
|
reindexTree(rootID, i, size)
|
||||||
continue
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
duplicatedRootIDs := sql.GetDuplicatedRootIDs()
|
duplicatedRootIDs := sql.GetDuplicatedRootIDs()
|
||||||
for _, rootID := range duplicatedRootIDs {
|
size := len(duplicatedRootIDs)
|
||||||
|
for i, rootID := range duplicatedRootIDs {
|
||||||
root := sql.GetBlock(rootID)
|
root := sql.GetBlock(rootID)
|
||||||
if nil == root {
|
if nil == root {
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -581,15 +581,19 @@ func GetBlock(id string) (ret *Block) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRootUpdated(rootID string) (ret string, err error) {
|
func GetRootUpdated() (ret map[string]string, err error) {
|
||||||
rows, err := query("SELECT updated FROM blocks WHERE root_id = ? AND type = 'd'", rootID)
|
rows, err := query("SELECT root_id, updated FROM blocks 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
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
|
ret = map[string]string{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
rows.Scan(&ret)
|
var rootID, updated string
|
||||||
|
rows.Scan(&rootID, &updated)
|
||||||
|
ret[rootID] = updated
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue