⚡ Improve performance for rendering databases, due flashcards
This commit is contained in:
parent
65f24b376e
commit
06f3721fd4
6 changed files with 36 additions and 7 deletions
|
@ -244,7 +244,7 @@ func openNotebook(c *gin.Context) {
|
|||
"20240530133126-axarxgx": "20240530101000-4qitucx",
|
||||
}
|
||||
startID = guideStartID[notebook]
|
||||
if nil != treenode.GetBlockTree(startID) {
|
||||
if treenode.ExistBlockTree(startID) {
|
||||
util.BroadcastByTypeAndApp("main", app, "openFileById", 0, "", map[string]interface{}{
|
||||
"id": startID,
|
||||
})
|
||||
|
|
|
@ -199,7 +199,7 @@ func GetAttributeViewPrimaryKeyValues(avID, keyword string, page, pageSize int)
|
|||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
if !kv.IsDetached {
|
||||
if nil == treenode.GetBlockTree(kv.BlockID) {
|
||||
if !treenode.ExistBlockTree(kv.BlockID) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,17 +71,17 @@ func GetDocInfo(blockID string) (ret *BlockInfo) {
|
|||
delete(ret.IAL, "scroll")
|
||||
} else {
|
||||
if zoomInId := scroll["zoomInId"]; nil != zoomInId {
|
||||
if nil == treenode.GetBlockTree(zoomInId.(string)) {
|
||||
if !treenode.ExistBlockTree(zoomInId.(string)) {
|
||||
delete(ret.IAL, "scroll")
|
||||
}
|
||||
} else {
|
||||
if startId := scroll["startId"]; nil != startId {
|
||||
if nil == treenode.GetBlockTree(startId.(string)) {
|
||||
if !treenode.ExistBlockTree(startId.(string)) {
|
||||
delete(ret.IAL, "scroll")
|
||||
}
|
||||
}
|
||||
if endId := scroll["endId"]; nil != endId {
|
||||
if nil == treenode.GetBlockTree(endId.(string)) {
|
||||
if !treenode.ExistBlockTree(endId.(string)) {
|
||||
delete(ret.IAL, "scroll")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1085,7 +1085,7 @@ func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCar
|
|||
continue
|
||||
}
|
||||
|
||||
if nil == treenode.GetBlockTree(c.BlockID()) {
|
||||
if !treenode.ExistBlockTree(c.BlockID()) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -111,6 +111,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
|||
|
||||
// 过滤掉不存在的行
|
||||
var notFound []string
|
||||
var toCheckBlockIDs []string
|
||||
for blockID, keyValues := range rows {
|
||||
blockValue := getRowBlockValue(keyValues)
|
||||
if nil == blockValue {
|
||||
|
@ -127,7 +128,11 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
|||
continue
|
||||
}
|
||||
|
||||
if nil == treenode.GetBlockTree(blockID) {
|
||||
toCheckBlockIDs = append(toCheckBlockIDs, blockID)
|
||||
}
|
||||
checkRet := treenode.ExistBlockTrees(toCheckBlockIDs)
|
||||
for blockID, exist := range checkRet {
|
||||
if !exist {
|
||||
notFound = append(notFound, blockID)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -304,6 +304,30 @@ func ExistBlockTree(id string) bool {
|
|||
return 0 < count
|
||||
}
|
||||
|
||||
func ExistBlockTrees(ids []string) (ret map[string]bool) {
|
||||
ret = map[string]bool{}
|
||||
for _, id := range ids {
|
||||
ret[id] = false
|
||||
}
|
||||
|
||||
sqlStmt := "SELECT id FROM blocktrees WHERE id IN ('" + strings.Join(ids, "','") + "')"
|
||||
rows, err := db.Query(sqlStmt)
|
||||
if nil != err {
|
||||
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var id string
|
||||
if err = rows.Scan(&id); nil != err {
|
||||
logging.LogErrorf("query scan field failed: %s", err)
|
||||
return
|
||||
}
|
||||
ret[id] = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetBlockTrees(ids []string) (ret map[string]*BlockTree) {
|
||||
ret = map[string]*BlockTree{}
|
||||
sqlStmt := "SELECT * FROM blocktrees WHERE id IN ('" + strings.Join(ids, "','") + "')"
|
||||
|
|
Loading…
Add table
Reference in a new issue