♻️ Adjust addRiffCards/removeRiffCards implementation to be asynchronous transaction https://github.com/siyuan-note/siyuan/issues/7936

This commit is contained in:
Liang Ding 2023-04-09 23:00:09 +08:00
parent e5143a8474
commit 3e14b4f29c
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 58 additions and 104 deletions

View file

@ -216,13 +216,22 @@ func removeRiffCards(c *gin.Context) {
for _, blockID := range blockIDsArg {
blockIDs = append(blockIDs, blockID.(string))
}
err := model.RemoveFlashcardsByBlockIDs(deckID, blockIDs)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()
return
transactions := []*model.Transaction{
{
DoOperations: []*model.Operation{
{
Action: "removeFlashcards",
DeckID: deckID,
BlockIDs: blockIDs,
},
},
},
}
model.PerformTransactions(&transactions)
model.WaitForWritingFiles()
if "" != deckID {
deck := model.Decks[deckID]
ret.Data = deckData(deck)
@ -245,13 +254,22 @@ func addRiffCards(c *gin.Context) {
for _, blockID := range blockIDsArg {
blockIDs = append(blockIDs, blockID.(string))
}
err := model.AddFlashcards(deckID, blockIDs)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()
return
transactions := []*model.Transaction{
{
DoOperations: []*model.Operation{
{
Action: "addFlashcards",
DeckID: deckID,
BlockIDs: blockIDs,
},
},
},
}
model.PerformTransactions(&transactions)
model.WaitForWritingFiles()
deck := model.Decks[deckID]
ret.Data = deckData(deck)
}