WebSQL性能问题 - 更新大量数据

时间:2013-04-02 13:45:02

标签: database html5 web-sql

我有一些代码可以更新某些webSQL表,但它是另一个事务中的另一个事务中的事务。更新表需要相当长的时间,但创建/插入值需要一段正常的时间。有没有办法看到webSQL事务的性能(需要多长时间?)

在AJAX Sucess内部回调到webService我有以下代码:

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);
    });

}

1 个答案:

答案 0 :(得分:0)

重复使用这些交易,你应该会看到性能的显着提升。

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

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

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