优化统计

This commit is contained in:
2026-03-10 11:24:39 +08:00
parent 244013f99f
commit f53669d048
3 changed files with 7 additions and 4 deletions
@@ -182,10 +182,14 @@ object ObjectBox {
}
// 使用 QueryBuilder 在数据库层计数,避免全量加载到内存
suspend fun count(name: String) = safeDbOp {
suspend fun countNameField(name: String) = safeDbOp {
getBox<Food>()?.query(Food_.name.equal(name))?.build()?.count()
} ?: 0L
suspend fun countIndexField(idx: Int) = safeDbOp {
getBox<Food>()?.query(Food_.foodIdx.equal(idx))?.build()?.count()
} ?: 0L
// 使用 QueryBuilder 在数据库层过滤,避免全量加载到内存
suspend fun filter(name: String?) = safeDbOp {
if (!name.isNullOrBlank()) {