【发布时间】:2017-09-24 21:08:41
【问题描述】:
我的 react 本机应用程序中有类似以下代码来设置模拟/测试数据以进行性能测试。
realm.write(() => {
const max = 120;
for(let x=1; x<=max; x++)
{
realm.create('Product', {productId:x});
}
for(let x=1; x<=max; x++)
{
for(let y=x; y<=max; y++)
{
for(let z=y; z<=max; z++)
{
realm.create('Compatibility', {
result: 'Y '+x+' '+y+' '+z,
products: [
realm.objects('Product').filtered('productId = '+x)[0],
realm.objects('Product').filtered('productId = '+y)[0],
realm.objects('Product').filtered('productId = '+z)[0]
]
});
}
}
}
});
class Product {}
Product.schema = {
name: 'Product',
primaryKey:'productId',
properties: {
productId:'int'
}
};
class Compatibility {}
Compatibility.schema = {
name: 'Compatibility',
properties: {
result: {type: 'string'},
products: {type: 'list',objectType:'Product'},
}
};
这意味着 Products 对象有 120 条记录,而 Compatibility 对象有 170 万条记录。
当我运行查询 realm.objects('Compatibility').filtered(products.productId = 3 AND products.productId = 25 AND products.productId = 97) 时,在我的旧 HTC Desire 510 和我的华为 Nova Plus 上运行大约需要 15 秒。这太慢了。
有没有办法提高查询速度?例如,你能索引列吗?
【问题讨论】:
标签: react-native realm