mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-04 11:50:15 +01:00
🎨 Improve assets data index updating after data sync on mobile https://github.com/siyuan-note/siyuan/issues/16747
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
14b6eb42f4
commit
911a9d0ad0
3 changed files with 30 additions and 1 deletions
|
|
@ -65,11 +65,19 @@ func GetAssetPathByHash(hash string) string {
|
|||
}
|
||||
|
||||
func HandleAssetsRemoveEvent(assetAbsPath string) {
|
||||
if !filelock.IsExist(assetAbsPath) {
|
||||
return
|
||||
}
|
||||
|
||||
removeIndexAssetContent(assetAbsPath)
|
||||
removeAssetThumbnail(assetAbsPath)
|
||||
}
|
||||
|
||||
func HandleAssetsChangeEvent(assetAbsPath string) {
|
||||
if !filelock.IsExist(assetAbsPath) {
|
||||
return
|
||||
}
|
||||
|
||||
indexAssetContent(assetAbsPath)
|
||||
removeAssetThumbnail(assetAbsPath)
|
||||
}
|
||||
|
|
@ -694,7 +702,11 @@ func RemoveUnusedAssets() (ret []string) {
|
|||
util.PushErrMsg(fmt.Sprintf("%s", removeErr), 7000)
|
||||
return
|
||||
}
|
||||
|
||||
util.RemoveAssetText(unusedAsset)
|
||||
if !isFileWatcherAvailable() {
|
||||
HandleAssetsRemoveEvent(absPath)
|
||||
}
|
||||
}
|
||||
ret = append(ret, absPath)
|
||||
}
|
||||
|
|
@ -739,6 +751,9 @@ func RemoveUnusedAsset(p string) (ret string) {
|
|||
ret = absPath
|
||||
|
||||
util.RemoveAssetText(p)
|
||||
if !isFileWatcherAvailable() {
|
||||
HandleAssetsRemoveEvent(absPath)
|
||||
}
|
||||
|
||||
IncSync()
|
||||
|
||||
|
|
|
|||
|
|
@ -30,10 +30,14 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func isFileWatcherAvailable() bool {
|
||||
return util.ContainerAndroid != util.Container && util.ContainerIOS != util.Container && util.ContainerHarmony != util.Container
|
||||
}
|
||||
|
||||
var assetsWatcher *fsnotify.Watcher
|
||||
|
||||
func WatchAssets() {
|
||||
if util.ContainerAndroid == util.Container || util.ContainerIOS == util.Container || util.ContainerHarmony == util.Container {
|
||||
if !isFileWatcherAvailable() {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1635,6 +1635,11 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
|
|||
if strings.HasSuffix(file.Path, ".sy") {
|
||||
upsertTrees++
|
||||
}
|
||||
|
||||
if !isFileWatcherAvailable() && strings.HasPrefix(file.Path, "/assets/") {
|
||||
absPath := filepath.Join(util.DataDir, file.Path)
|
||||
HandleAssetsChangeEvent(absPath)
|
||||
}
|
||||
}
|
||||
|
||||
removeWidgetDirSet, unloadPluginSet, uninstallPluginSet := hashset.New(), hashset.New(), hashset.New()
|
||||
|
|
@ -1676,6 +1681,11 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
|
|||
removeWidgetDirSet.Add(parts[2])
|
||||
}
|
||||
}
|
||||
|
||||
if !isFileWatcherAvailable() && strings.HasPrefix(file.Path, "/assets/") {
|
||||
absPath := filepath.Join(util.DataDir, file.Path)
|
||||
HandleAssetsRemoveEvent(absPath)
|
||||
}
|
||||
}
|
||||
|
||||
for _, upsertPetal := range mergeResult.UpsertPetals {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue