I am using JayData 1.3.5 Pro in my HTML5 application to connect to IndexDB.
I have a PRODUCTS (contextEntity) table and I am using the following query to retrieve 15839 records from the same table.
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 = [];
}
});
Now what happens is, it takes 30 seconds to retrive results for the search input. Is there a way to optimize this code so that I can retreive the search results faster like in 3 seconds. I am trying to find an alternate for toArray / toLiveArray.
Please suggest an alternate approach to improve the performance.
Thanks,
Sriram