An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 改进闪卡存储数据结构,支持一个块对应多张闪卡 https://github.com/siyuan-note/siyuan/issues/7417
Liang Ding127327060fd4
diff --git a/kernel/model/block.go b/kernel/model/block.goindex 066c3a8f70..5fe311a1fd 100644--- a/kernel/model/block.go+++ b/kernel/model/block.go@@ -60,6 +60,8 @@ type Block struct {Sort int `json:"sort"`Created string `json:"created"`Updated string `json:"updated"`++ RiffCardID string `json:"riffCardID"`}func (block *Block) IsContainerBlock() bool {diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.goindex 11be65d0bd..8afc132a49 100644--- a/kernel/model/flashcard.go+++ b/kernel/model/flashcard.go@@ -43,8 +43,6 @@ var deckLock = sync.Mutex{}func GetTreeFlashcards(rootID string, page int) (blocks []*Block, total, pageCount int) {blocks = []*Block{}-- const pageSize = 20deck := Decks[builtinDeckID]if nil == deck {return@@ -59,49 +57,19 @@ func GetTreeFlashcards(rootID string, page int) (blocks []*Block, total, pageCou}}allBlockIDs = gulu.Str.RemoveDuplicatedElem(allBlockIDs)- sort.Strings(allBlockIDs)+ cards := deck.GetCardsByBlockIDs(allBlockIDs)- start := (page - 1) * pageSize- end := page * pageSize- if start > len(allBlockIDs) {- start = len(allBlockIDs)- }- if end > len(allBlockIDs) {- end = len(allBlockIDs)- }- blockIDs := allBlockIDs[start:end]- total = len(allBlockIDs)- pageCount = int(math.Ceil(float64(total) / float64(pageSize)))- if 1 > len(blockIDs) {- blocks = []*Block{}- return- }-- sqlBlocks := sql.GetBlocks(blockIDs)- blocks = fromSQLBlocks(&sqlBlocks, "", 36)- if 1 > len(blocks) {- blocks = []*Block{}- return- }-- for i, b := range blocks {- if nil == b {- blocks[i] = &Block{- ID: blockIDs[i],- Content: Conf.Language(180),- }- }- }+ blocks, total, pageCount = getCardsBlocks(cards, page)return}func GetFlashcards(deckID string, page int) (blocks []*Block, total, pageCount int) {blocks = []*Block{}- var allBlockIDs []string- const pageSize = 20+ var cards []riff.Cardif "" == deckID {for _, deck := range Decks {- allBlockIDs = append(allBlockIDs, deck.GetBlockIDs()...)+ blockIDs := deck.GetBlockIDs()+ cards = append(cards, deck.GetCardsByBlockIDs(blockIDs)...)}} else {deck := Decks[deckID]@@ -109,28 +77,38 @@ func GetFlashcards(deckID string, page int) (blocks []*Block, total, pageCount ireturn}- allBlockIDs = append(allBlockIDs, deck.GetBlockIDs()...)+ blockIDs := deck.GetBlockIDs()+ cards = append(cards, deck.GetCardsByBlockIDs(blockIDs)...)}- allBlockIDs = gulu.Str.RemoveDuplicatedElem(allBlockIDs)- sort.Strings(allBlockIDs)+ blocks, total, pageCount = getCardsBlocks(cards, page)+ return+}+func getCardsBlocks(cards []riff.Card, page int) (blocks []*Block, total, pageCount int) {+ const pageSize = 20start := (page - 1) * pageSizeend := page * pageSize- if start > len(allBlockIDs) {- start = len(allBlockIDs)+ if start > len(cards) {+ start = len(cards)}- if end > len(allBlockIDs) {- end = len(allBlockIDs)+ if end > len(cards) {+ end = len(cards)}- blockIDs := allBlockIDs[start:end]- total = len(allBlockIDs)+ cardIDs := cards[start:end]+ total = len(cards)pageCount = int(math.Ceil(float64(total) / float64(pageSize)))- if 1 > len(blockIDs) {+ if 1 > len(cardIDs) {blocks = []*Block{}return}+ var blockIDs []string+ for _, card := range cards {+ blockIDs = append(blockIDs, card.BlockID())+ }+ sort.Strings(blockIDs)+sqlBlocks := sql.GetBlocks(blockIDs)blocks = fromSQLBlocks(&sqlBlocks, "", 36)if 1 > len(blocks) {@@ -144,7 +122,11 @@ func GetFlashcards(deckID string, page int) (blocks []*Block, total, pageCount iID: blockIDs[i],Content: Conf.Language(180),}++ continue}++ b.RiffCardID = cards[i].ID()}return}