🎨 将删除文档放到任务队列中执行

This commit is contained in:
Liang Ding 2023-01-19 21:36:56 +08:00
parent 01a3a14ef6
commit aad7dedc97
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
7 changed files with 27 additions and 43 deletions

View file

@ -945,7 +945,7 @@
"67": "Uploaded at %s, downloaded at %s",
"68": "The local data has exceeded the maximum storage capacity of cloud space [%s] during the trial period, and cannot continue to sync data. After the subscription, the cloud storage capacity will be upgraded to [8 GB]",
"69": "Download completed",
"70": "Copy notebook [%s] file [%s] failed: %s",
"70": "TODO",
"71": "Failed to insert asset file, please reopen the document",
"72": "Content has been copied to the system clipboard, please go to SiYuan to paste",
"73": "Importing, please wait...",

View file

@ -945,7 +945,7 @@
"67": "Cargado en %s, descargado en %s",
"68": "Les données locales ont dépassé la capacité de stockage maximale de l'espace cloud [%s] pendant la période d'essai et ne peuvent pas continuer à synchroniser les données. Después de la suscripción, la capacidad de almacenamiento en la nube se actualizará a 8GB",
"69": "Descarga completada",
"70": "Error en la copia del cuaderno [%s] del archivo [%s]: %s",
"70": "TODO",
"71": "Fallo en la inserción del archivo de activos, por favor reabra el documento",
"72": "El contenido se ha copiado en el portapapeles del sistema, por favor vaya a SiYuan para pegar",
"73": "Importando, por favor espere...",

View file

@ -945,7 +945,7 @@
"67": "Transféré à %s, téléchargé à %s",
"68": "Les données locales ont dépassé la capacité de stockage maximale [%s] de l'espace cloud pendant la période d'essai, et les données ne peuvent plus être téléchargées. Après l'abonnement, la capacité de stockage cloud sera mise à niveau à 8GB",
"69": "Téléchargement terminé",
"70": "La copie du carnet de notes [%s] du fichier [%s] a échoué : %s",
"70": "TODO",
"71": "L'insertion du fichier asset a échoué, veuillez rouvrir le document.",
"72": "Le contenu a été copié dans le presse-papiers du système, veuillez vous rendre sur SiYuan pour le coller.",
"73": "En cours d'importation, veuillez patienter...",

View file

@ -945,7 +945,7 @@
"67": "上傳於 %s下載於 %s",
"68": "本地數據已超過試用期雲端空間最大存儲容量 [%s],無法繼續同步數據,訂閱後雲端存儲容量將升級為 8GB",
"69": "下載完畢",
"70": "複製筆記本 [%s] 下的檔 [%s] 失敗:%s",
"70": "TODO",
"71": "插入資料檔失敗,請重新打開文檔",
"72": "內容已經複製到系統剪貼簿,請到思源中進行貼上",
"73": "正在導入,請稍等...",

View file

@ -945,7 +945,7 @@
"67": "上传于 %s下载于 %s",
"68": "本地数据已超过试用期云端空间最大存储容量 [%s],无法继续同步数据,<a target='_blank' href='https://ld246.com/subscribe/siyuan'>订阅</a>后云端存储容量将升级为 [8 GB]",
"69": "下载完毕",
"70": "复制笔记本 [%s] 下的文件 [%s] 失败:%s",
"70": "TODO",
"71": "插入资源文件失败,请重新打开文档",
"72": "内容已经复制到系统剪切板,请到思源中进行粘贴",
"73": "正在导入,请稍等...",

View file

@ -275,13 +275,7 @@ func removeDoc(c *gin.Context) {
notebook := arg["notebook"].(string)
p := arg["path"].(string)
err := model.RemoveDoc(notebook, p)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()
return
}
model.RemoveDoc(notebook, p)
}
func removeDocs(c *gin.Context) {
@ -298,12 +292,7 @@ func removeDocs(c *gin.Context) {
for _, path := range pathsArg {
paths = append(paths, path.(string))
}
err := model.RemoveDocs(paths)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()
return
}
model.RemoveDocs(paths)
}
func renameDoc(c *gin.Context) {

View file

@ -43,6 +43,7 @@ import (
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/search"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/task"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -1177,23 +1178,19 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string) (newPath
return
}
func RemoveDoc(boxID, p string) (err error) {
func RemoveDoc(boxID, p string) {
box := Conf.Box(boxID)
if nil == box {
err = errors.New(Conf.Language(0))
return
}
WaitForWritingFiles()
err = removeDoc(box, p)
if nil != err {
return
}
removeDoc(box, p)
IncSync()
return
}
func RemoveDocs(paths []string) (err error) {
func RemoveDocs(paths []string) {
util.PushEndlessProgress(Conf.Language(116))
defer util.PushClearProgress()
@ -1201,17 +1198,14 @@ func RemoveDocs(paths []string) (err error) {
pathsBoxes := getBoxesByPaths(paths)
WaitForWritingFiles()
for p, box := range pathsBoxes {
err = removeDoc(box, p)
if nil != err {
return
}
removeDoc(box, p)
}
return
}
func removeDoc(box *Box, p string) (err error) {
tree, err := LoadTree(box.ID, p)
if nil != err {
func removeDoc(box *Box, p string) {
tree, _ := LoadTree(box.ID, p)
if nil == tree {
return
}
@ -1224,15 +1218,13 @@ func removeDoc(box *Box, p string) (err error) {
historyPath := filepath.Join(historyDir, box.ID, p)
absPath := filepath.Join(util.DataDir, box.ID, p)
if err = filelock.Copy(absPath, historyPath); nil != err {
return errors.New(fmt.Sprintf(Conf.Language(70), box.Name, absPath, err))
logging.LogErrorf("backup [path=%s] to history [%s] failed: %s", absPath, historyPath, err)
return
}
copyDocAssetsToDataAssets(box.ID, p)
var removeIDs []string
ids := treenode.RootChildIDs(tree.ID)
removeIDs = append(removeIDs, ids...)
removeIDs := treenode.RootChildIDs(tree.ID)
dir := path.Dir(p)
childrenDir := path.Join(dir, tree.ID)
existChildren := box.Exist(childrenDir)
@ -1240,6 +1232,7 @@ func removeDoc(box *Box, p string) (err error) {
absChildrenDir := filepath.Join(util.DataDir, tree.Box, childrenDir)
historyPath = filepath.Join(historyDir, tree.Box, childrenDir)
if err = filelock.Copy(absChildrenDir, historyPath); nil != err {
logging.LogErrorf("backup [path=%s] to history [%s] failed: %s", absChildrenDir, historyPath, err)
return
}
}
@ -1254,11 +1247,7 @@ func removeDoc(box *Box, p string) (err error) {
return
}
box.removeSort(removeIDs)
treenode.RemoveBlockTreesByPathPrefix(childrenDir)
sql.RemoveTreePathQueue(box.ID, childrenDir)
RemoveRecentDoc(removeIDs)
if "/" != dir {
others, err := os.ReadDir(filepath.Join(util.DataDir, box.ID, dir))
if nil == err && 1 > len(others) {
@ -1266,13 +1255,19 @@ func removeDoc(box *Box, p string) (err error) {
}
}
cache.RemoveDocIAL(p)
evt := util.NewCmdResult("removeDoc", 0, util.PushModeBroadcast)
evt.Data = map[string]interface{}{
"ids": removeIDs,
}
util.PushEvent(evt)
task.PrependTask(task.DatabaseIndex, removeDoc0, box, p, childrenDir)
}
func removeDoc0(box *Box, p, childrenDir string) {
treenode.RemoveBlockTreesByPathPrefix(childrenDir)
sql.RemoveTreePathQueue(box.ID, childrenDir)
cache.RemoveDocIAL(p)
return
}