优化向量查询,替换新模型
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user