diff --git a/app/changelogs/v2.10.6/v2.10.6.md b/app/changelogs/v2.10.6/v2.10.6.md new file mode 100644 index 000000000..202fd2105 --- /dev/null +++ b/app/changelogs/v2.10.6/v2.10.6.md @@ -0,0 +1,12 @@ +## Overview + +This version fixes some defects, it is recommended to upgrade. + +Advertisement: Currently, `PRO Features` are in the early bird price stage, welcome to [learn more](https://b3log.org/siyuan/pricing.html). + +Note: The annual `Subscription` includes `Pro features`. If you are an annual subscriber, you do not need to buy PRO Features separately. + +## Changelogs + +Below are the detailed changes in this version. + diff --git a/app/changelogs/v2.10.6/v2.10.6_zh_CHT.md b/app/changelogs/v2.10.6/v2.10.6_zh_CHT.md new file mode 100644 index 000000000..1feca8642 --- /dev/null +++ b/app/changelogs/v2.10.6/v2.10.6_zh_CHT.md @@ -0,0 +1,11 @@ +## 概述 + +該版本修復了一些缺陷,建議升級。 + +廣告: 目前 `功能特性` 正處於早鳥價階段,歡迎[了解](https://b3log.org/siyuan/pricing.html)。 + +注:`年付訂閱` 包含 `功能特性`,如果你是訂閱會員,則無需單獨購買功能特性。 + +## 變更記錄 + +以下是此版本中的詳細變更。 \ No newline at end of file diff --git a/app/changelogs/v2.10.6/v2.10.6_zh_CN.md b/app/changelogs/v2.10.6/v2.10.6_zh_CN.md new file mode 100644 index 000000000..c6c65a14c --- /dev/null +++ b/app/changelogs/v2.10.6/v2.10.6_zh_CN.md @@ -0,0 +1,13 @@ +## 概述 + +该版本修复了一些缺陷,建议升级。 + +广告: 目前 `功能特性` 正处于早鸟价阶段,欢迎[了解](https://b3log.org/siyuan/pricing.html)。 + +注:`年付订阅` 包含 `功能特性`,如果你是订阅会员,则无需单独购买功能特性。 + +## 变更记录 + +以下是此版本中的详细变更。 + + diff --git a/kernel/api/transaction.go b/kernel/api/transaction.go index 2d4b84b98..ba6dbc2a3 100644 --- a/kernel/api/transaction.go +++ b/kernel/api/transaction.go @@ -53,12 +53,16 @@ func performTransactions(c *gin.Context) { return } + timestamp := int64(arg["reqId"].(float64)) var transactions []*model.Transaction if err = gulu.JSON.UnmarshalJSON(data, &transactions); nil != err { ret.Code = -1 ret.Msg = "parses request failed" return } + for _, transaction := range transactions { + transaction.Timestamp = timestamp + } model.PerformTransactions(&transactions) diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 1a6f64913..90efbf22c 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -18,8 +18,10 @@ package model import ( "bytes" + "errors" "fmt" "path/filepath" + "sort" "strings" "sync" "time" @@ -152,6 +154,9 @@ func mergeTx() (ret *Transaction) { func PerformTransactions(transactions *[]*Transaction) { txQueueLock.Lock() txQueue = append(txQueue, *transactions...) + sort.Slice(txQueue, func(i, j int) bool { + return txQueue[i].Timestamp < txQueue[j].Timestamp + }) txQueueLock.Unlock() return } @@ -449,9 +454,9 @@ func (tx *Transaction) doPrependInsert(operation *Operation) (ret *TxErr) { var err error block := treenode.GetBlockTree(operation.ParentID) if nil == block { - msg := fmt.Sprintf("not found parent block [%s]", operation.ParentID) - logging.LogErrorf(msg) - return &TxErr{code: TxErrCodeBlockNotFound, id: operation.ParentID} + logging.LogWarnf("not found block [%s]", operation.ParentID) + util.ReloadUI() // 比如分屏后编辑器状态不一致,这里强制重新载入界面 + return } tree, err := tx.loadTree(block.ID) if nil != err { @@ -533,9 +538,9 @@ func (tx *Transaction) doAppendInsert(operation *Operation) (ret *TxErr) { var err error block := treenode.GetBlockTree(operation.ParentID) if nil == block { - msg := fmt.Sprintf("not found parent block [%s]", operation.ParentID) - logging.LogErrorf(msg) - return &TxErr{code: TxErrCodeBlockNotFound, id: operation.ParentID} + logging.LogWarnf("not found block [%s]", operation.ParentID) + util.ReloadUI() // 比如分屏后编辑器状态不一致,这里强制重新载入界面 + return } tree, err := tx.loadTree(block.ID) if nil != err { @@ -692,11 +697,12 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) { var err error id := operation.ID tree, err := tx.loadTree(id) - if ErrBlockNotFound == err { - return nil // move 以后这里会空,算作正常情况 - } - if nil != err { + if errors.Is(err, ErrBlockNotFound) { + // move 以后这里会空,算作正常情况 + return + } + msg := fmt.Sprintf("load tree [%s] failed: %s", id, err) logging.LogErrorf(msg) return &TxErr{code: TxErrCodeBlockNotFound, id: id} @@ -773,9 +779,9 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) { } } if nil == block { - msg := fmt.Sprintf("not found next block [%s]", operation.NextID) - logging.LogErrorf(msg) - return &TxErr{code: TxErrCodeBlockNotFound, id: operation.NextID} + logging.LogWarnf("not found block [%s, %s, %s]", operation.ParentID, operation.PreviousID, operation.NextID) + util.ReloadUI() // 比如分屏后编辑器状态不一致,这里强制重新载入界面 + return } tree, err := tx.loadTree(block.ID) @@ -919,9 +925,13 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) { func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) { id := operation.ID - tree, err := tx.loadTree(id) if nil != err { + if errors.Is(err, ErrBlockNotFound) { + logging.LogWarnf("not found block [%s]", id) + return + } + logging.LogErrorf("load tree [%s] failed: %s", id, err) return &TxErr{code: TxErrCodeBlockNotFound, id: id} } @@ -1101,6 +1111,7 @@ type Operation struct { } type Transaction struct { + Timestamp int64 `json:"timestamp"` DoOperations []*Operation `json:"doOperations"` UndoOperations []*Operation `json:"undoOperations"`