Improve performance for rendering databases, due flashcards

This commit is contained in:
Daniel 2024-06-23 21:37:28 +08:00
parent 65f24b376e
commit 06f3721fd4
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
6 changed files with 36 additions and 7 deletions

View file

@ -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, "','") + "')"