0

我有一些代码可以更新一些 webSQL 表,但是它是另一个事务中的一个事务,另一个事务中的一个事务。更新表需要很长时间,但创建/插入值需要正常的时间。有什么方法可以查看 webSQL 事务的性能(需要多长时间?)

在对 webService 的 AJAX Sucess 回调中,我有以下代码:

function handleOrderNote(value, tx, ite) {
tx.executeSql('SELECT * FROM MobileOrder where MobileOrderID = ?', [value.mobileOrder.mobileOrderID],
    function (tx, result) {
        function updateCreateOrderNote(tx, result, nResultadosIn, ite) {
            if (nResultadosIn > 0) {
                function updateOrderNote(value2, tx, ite) {
                    tx.executeSql('UPDATE MobileOrder SET CompanyID =?, CustomerID =?, OrderDate = ?, TotalQtt = ?, TotalCost = ?, UserPHC=?, HeaderID=?, OrderState=?, Observations=?, Status = ? WHERE MobileOrderID = ?', [value2.mobileOrder.companyID, value2.mobileOrder.customerID, value2.mobileOrder.orderDate, value2.mobileOrder.totalQtt, value2.mobileOrder.totalCost, value2.mobileOrder.userPHC, value2.mobileOrder.headerID, value2.mobileOrder.orderState, value2.mobileOrder.observations, value2.mobileOrder.status, value2.mobileOrder.mobileOrderID],
                        function (tx, result) {
                            function searchEqualOrderNote(value3, tx, ite) {
                                tx.executeSql('SELECT * FROM MobileOrderDetail where MobileOrderDetailID = ?', [value3.mobileOrderDetailID],
                                    function (tx, result) {
                                        function updateCreateLineOrderNote(tx, result, nResultadosIn, ite, value3) {
                                            if (nResultadosIn > 0) {
                                                function updateLineOrderNote(value4, tx, ite) {
                                                    tx.executeSql('UPDATE MobileOrderDetail SET MobileOrderID =?, Ref =?, CompanyID = ?, Discount = ?, Qtt = ?, TotalDetail=?, DetailID=? WHERE MobileOrderDetailID = ?', [value4.mobileOrderID, value4.ref, value4.companyID, value4.discount, value4.qtt, value4.totalDetail, value4.detailID, value4.mobileOrderDetailID],
                                                        function (tx, result) {}
                                                    );
                                                }
                                                updateLineOrderNote(value3, tx, ite);
                                            } else {
                                                function createLineOrderNote(value4, tx, ite) {
                                                    tx.executeSql('INSERT INTO MobileOrderDetail (MobileOrderDetailID, MobileOrderID, Ref, CompanyID, Discount, Qtt, TotalDetail, DetailID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', [value4.mobileOrderDetailID, value4.mobileOrderID, value4.ref, value4.companyID, value4.discount, value4.qtt, value4.totalDetail, value4.detailID],
                                                        function (tx, result) {});
                                                }
                                                createLineOrderNote(value3, tx, ite);
                                            }
                                        }

                                        updateCreateLineOrderNote(tx, result, result.rows.length, ite, value3);
                                    });
                            }
                            for (var i = 0; i < value2.mobileOrderDetail.length; i++) {
                                var linhaNotaEncomenda = value2.mobileOrderDetail[i];
                                searchEqualOrderNote(linhaNotaEncomenda, tx, i);
                            }
                        }
                    );
                }
                updateOrderNote(value, tx, ite);
            } else {
                function createOrderNote(value2, tx, ite) {
                    tx.executeSql('INSERT INTO MobileOrder (IDLocal, MobileOrderID, CompanyID, CustomerID, OrderDate, TotalQtt, TotalCost, UserPHC, HeaderID, OrderState, Observations, Status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [idLocalDestaEncomenda, value2.mobileOrder.mobileOrderID, value2.mobileOrder.companyID, value2.mobileOrder.customerID, value2.mobileOrder.orderDate, value2.mobileOrder.totalQtt, value2.mobileOrder.totalCost, value2.mobileOrder.userPHC, value2.mobileOrder.headerID, value2.mobileOrder.orderState, value2.mobileOrder.observations, value2.mobileOrder.status],
                        function (tx, result) {
                            function searchEqualOrderNote(value3, tx, ite, idLocalInput) {
                                tx.executeSql('SELECT * FROM MobileOrderDetail where MobileOrderDetailID = ?', [value3.mobileOrderDetailID],
                                    function (tx, result) {
                                        function updateCreateLineOrderNote(tx, result, nResultadosIn, ite, value3) {
                                            if (nResultadosIn > 0) {
                                                function updateLineOrderNote(value4, tx, ite) {
                                                    tx.executeSql('UPDATE MobileOrderDetail SET MobileOrderID =?, Ref =?, CompanyID = ?, Discount = ?, Qtt = ?, TotalDetail=?, DetailID=? WHERE MobileOrderDetailID = ?', [value4.mobileOrderID, value4.ref, value4.companyID, value4.discount, value4.qtt, value4.totalDetail, value4.detailID, value4.mobileOrderDetailID],
                                                        function (tx, result) {}
                                                    );
                                                }
                                                updateOrderLine(value3, tx, ite);
                                            } else {
                                                function createLineOrderNote(value4, tx, ite) {
                                                    tx.executeSql('INSERT INTO MobileOrderDetail (MobileOrderDetailID, MobileOrderID, Ref, CompanyID, Discount, Qtt, TotalDetail, DetailID, IDLocal) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', [value4.mobileOrderDetailID, value4.mobileOrderID, value4.ref, value4.companyID, value4.discount, value4.qtt, value4.totalDetail, value4.detailID, idLocalInput],
                                                        function (tx, result) {
                                                            //trata linhas de encomenda
                                                        });
                                                }
                                                createLineOrderNote(value3, tx, ite);
                                            }
                                        }
                                        updateCreateLineOrderNote(tx, result, result.rows.length, ite, value3, idLocalInput);
                                    });
                            }
                            for (var i = 0; i < value2.mobileOrderDetail.length; i++) {
                                orderLine = value2.mobileOrderDetail[i];
                                searchEqualOrderNote(orderLine, tx, i, idLocalDestaEncomenda);
                            }
                        });
                }
                createOrderNote(value, tx, ite);
            }
        }
        updateCreateOrderNote(tx, result, result.rows.length, ite);
    });

}

4

1 回答 1

0

重用事务,您应该会看到性能的显着提升。

有两种方法可以重用事务。

通过使用来自 的多个 tx db.transaction,您可以获得并行请求。

通过重用来自 onsuccess 处理程序的 tx,您可以获得有序的串行请求。

于 2013-04-03T05:15:59.967 回答