【问题标题】:Performance improve on Jaydata filter and toArrayJaydata 过滤器和 toArray 的性能改进
【发布时间】: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 的替代方案。

请建议一种替代方法来提高性能。

谢谢, 斯里拉姆

【问题讨论】:

    标签: indexeddb web-sql jaydata


    【解决方案1】:

    在 IndexedDB(或任何数据库)中,只有两种查询方式。基于索引的查询和枚举 objectStore(或表)中的所有记录。

    基于索引的查询非常快,并且(几乎)与存储中的记录数量无关。

    随着记录数量的增加,枚举表中的所有记录会变慢。

    基于索引的查询要求您创建与您的查询匹配的索引。如果不需要排序,大部分查询都可以通过索引来完成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多