【发布时间】:2014-01-30 08:44:20
【问题描述】:
我在我的 HTML5 应用程序中使用 JayData 1.3.5 Pro 连接到 IndexDB。
我有一个 PRODUCTS (contextEntity) 表,我正在使用以下查询从同一个表中检索 15839 条记录。
dataContext.onReady(function () {
contextEntity
.filter(function (result) {
result.prod_num.toLowerCase.contains(this.prod_num) === -1 ||
result.vendor_name.toLowerCase.contains(this.vendor_name) === -1 ||
result.vendor_prod_num.toLowerCase.contains(this.vendor_prod_num) === -1 ||
result.desc1.toLowerCase.contains(this.desc1) === -1 ||
result.desc2.toLowerCase.contains(this.desc2) === -1 ||
result.desc3.toLowerCase.contains(this.desc3) === -1 ||
result.lookup.toLowerCase.contains(this.lookup) === -1 ||
result.icmastx_desc1.toLowerCase.contains(this.icmastx_desc1) === -1 ||
result.icmastx_desc5.toLowerCase.contains(this.icmastx_desc5) === -1 ||
result.icmastx_desc7.toLowerCase.contains(this.icmastx_desc7) === -1
},
{
prod_num: productPageProperty.search.toLowerCase(), // search input
vendor_name: productPageProperty.search.toLowerCase(),
vendor_prod_num: productPageProperty.search.toLowerCase(),
desc1: productPageProperty.search.toLowerCase(),
desc2: productPageProperty.search.toLowerCase(),
desc3: productPageProperty.search.toLowerCase(),
lookup: productPageProperty.search.toLowerCase(),
icmastx_desc1: productPageProperty.search.toLowerCase(),
icmastx_desc5: productPageProperty.search.toLowerCase(),
icmastx_desc7: productPageProperty.search.toLowerCase()
})
.toLiveArray(function (result) {
if (result != null && result.length > 0) {
result.forEach(function (item) {
productViewModel.push({
unit_conv: item.unit_conv,
cartid_sequence_num: null,
selling_disc: item.selling_disc,
pcat: item.pcat,
division_ck: item.division_ck,
uom: item.uom,
prod_num: item.prod_num,
desc1: item.desc1,
desc2: item.desc2,
net_avail: item.net_avail,
selling_price: item.selling_price,
cust_price: item.cust_price,
cust_disc: item.cust_disc,
qty_ordered: null,
extension: null
})
});
}
else {
productViewModel = [];
}
});
现在发生的情况是,检索搜索输入的结果需要 30 秒。有没有办法优化此代码,以便我可以在 3 秒内更快地检索搜索结果。我正在尝试寻找 toArray / toLiveArray 的替代方案。
请建议一种替代方法来提高性能。
谢谢, 斯里拉姆
【问题讨论】: