🎨 Distinguish between new cards and review cards during spaced repetition https://github.com/siyuan-note/siyuan/issues/9377

This commit is contained in:
Daniel 2023-12-21 09:21:57 +08:00
parent afbdb48ddf
commit ec46cebe77
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 14 additions and 10 deletions

View file

@ -434,6 +434,7 @@ type Flashcard struct {
DeckID string `json:"deckID"`
CardID string `json:"cardID"`
BlockID string `json:"blockID"`
State riff.State `json:"state"`
NextDues map[riff.Rating]string `json:"nextDues"`
}
@ -447,6 +448,7 @@ func newFlashcard(card riff.Card, blockID, deckID string, now time.Time) *Flashc
DeckID: deckID,
CardID: card.ID(),
BlockID: blockID,
State: card.GetState(),
NextDues: nextDues,
}
}
@ -632,7 +634,7 @@ func (tx *Transaction) doRemoveFlashcards(operation *Operation) (ret *TxErr) {
deckLock.Lock()
defer deckLock.Unlock()
if syncingStorages {
if syncingStorages.Load() {
ret = &TxErr{code: TxErrCodeDataIsSyncing}
return
}
@ -744,7 +746,7 @@ func (tx *Transaction) doAddFlashcards(operation *Operation) (ret *TxErr) {
deckLock.Lock()
defer deckLock.Unlock()
if syncingStorages {
if syncingStorages.Load() {
ret = &TxErr{code: TxErrCodeDataIsSyncing}
return
}
@ -991,6 +993,7 @@ func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCar
tmp = append(tmp, c)
}
dues = tmp
tmp = nil
for _, c := range dues {
if 0 < len(blockIDs) && !gulu.Str.Contains(c.BlockID(), blockIDs) {

View file

@ -31,6 +31,7 @@ import (
"sort"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/88250/gulu"
@ -934,10 +935,10 @@ func IndexRepo(memo string) (err error) {
}
var syncingFiles = sync.Map{}
var syncingStorages = false
var syncingStorages = atomic.Bool{}
func waitForSyncingStorages() {
for syncingStorages {
for syncingStorages.Load() {
time.Sleep(time.Second)
}
}
@ -1129,7 +1130,7 @@ func bootSyncRepo() (err error) {
}
syncingFiles = sync.Map{}
syncingStorages = false
syncingStorages.Store(false)
for _, fetchedFile := range fetchedFiles {
name := path.Base(fetchedFile.Path)
if strings.HasSuffix(name, ".sy") {
@ -1138,7 +1139,7 @@ func bootSyncRepo() (err error) {
continue
}
if strings.HasPrefix(fetchedFile.Path, "/storage/") {
syncingStorages = true
syncingStorages.Store(true)
}
}
@ -1362,7 +1363,7 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
}
syncingFiles = sync.Map{}
syncingStorages = false
syncingStorages.Store(false)
cache.ClearDocsIAL() // 同步后文档树文档图标没有更新 https://github.com/siyuan-note/siyuan/issues/4939
if needFullReindex(upsertTrees) { // 改进同步后全量重建索引判断 https://github.com/siyuan-note/siyuan/issues/5764