优化向量查询,替换新模型

This commit is contained in:
2026-03-10 13:33:31 +08:00
parent 1206ecd575
commit 1cc2358d72
6 changed files with 83 additions and 76 deletions
@@ -172,6 +172,12 @@ object ObjectBox {
getBox<Food>()?.get(id)
}
// 批量按ID加载,一次DB事务替代循环单条查询
suspend fun getByIds(ids: List<Long>): List<Food> = safeDbOp {
if (ids.isEmpty()) return@safeDbOp emptyList<Food>()
getBox<Food>()?.get(ids.toLongArray()) ?: emptyList<Food>()
} ?: emptyList()
suspend fun put(entity: Food) = safeDbOp {
getBox<Food>()?.put(entity)
}