🎨 Manually optimize the data index to reduce space usage and improve performance https://github.com/siyuan-note/siyuan/issues/15663

This commit is contained in:
Daniel 2025-08-25 11:23:42 +08:00
parent 8895613f8b
commit 34360fb9e3
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
15 changed files with 98 additions and 14 deletions

View file

@ -664,7 +664,46 @@ func normalizeTree(tree *parse.Tree) (yfmRootID, yfmTitle, yfmUpdated string) {
}
func VacuumDataIndex() {
util.PushEndlessProgress(Conf.language(270))
defer util.PushClearProgress()
var oldsyDbSize, newSyDbSize, oldHistoryDbSize, newHistoryDbSize, oldAssetContentDbSize, newAssetContentDbSize int64
info, _ := os.Stat(util.DBPath)
if nil != info {
oldsyDbSize = info.Size()
}
info, _ = os.Stat(util.HistoryDBPath)
if nil != info {
oldHistoryDbSize = info.Size()
}
info, _ = os.Stat(util.AssetContentDBPath)
if nil != info {
oldAssetContentDbSize = info.Size()
}
sql.Vacuum()
info, _ = os.Stat(util.DBPath)
if nil != info {
newSyDbSize = info.Size()
}
info, _ = os.Stat(util.HistoryDBPath)
if nil != info {
newHistoryDbSize = info.Size()
}
info, _ = os.Stat(util.AssetContentDBPath)
if nil != info {
newAssetContentDbSize = info.Size()
}
logging.LogInfof("vacuum database [siyuan.db: %s -> %s, history.db: %s -> %s, asset_content.db: %s -> %s]",
humanize.BytesCustomCeil(uint64(oldsyDbSize), 2), humanize.BytesCustomCeil(uint64(newSyDbSize), 2),
humanize.BytesCustomCeil(uint64(oldHistoryDbSize), 2), humanize.BytesCustomCeil(uint64(newHistoryDbSize), 2),
humanize.BytesCustomCeil(uint64(oldAssetContentDbSize), 2), humanize.BytesCustomCeil(uint64(newAssetContentDbSize), 2))
releaseSize := (oldsyDbSize - newSyDbSize) + (oldHistoryDbSize - newHistoryDbSize) + (oldAssetContentDbSize - newAssetContentDbSize)
msg := fmt.Sprintf(Conf.language(271), humanize.BytesCustomCeil(uint64(releaseSize), 2))
util.PushMsg(msg, 7000)
}
func FullReindex() {