You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We were trying to use sqlite workers to move our transaction to worker thread. We observed that, when we use db.transcations multiple times on iOS, the memory usage shots up unprecedentaly and reached upto 350 MB for simple insert/update and a select query in the end. Here is a sample code which simulates the actual code.
`importScripts('SQLitePlugin.js');
self.addEventListener('message', function(ev) {
if (ev.data === 'go') {
var i = 0;
sqlitePlugin.openDatabase({
name: 'testdb.db'
}, function(db) {
db.executeSql("Select Max(Prime) lastItem from test_table;", [], function(res) {
var nextRow = res.rows.item(0).lastItem + 1;
do {
i++;
nextRow++;
db.transaction(function(tx) {
var next=nextRow;
tx.executeSql("Update test_table set numberdata=2 where prime=?",[next],function(tx1, res) {
self.postMessage('Rows affected: ' + res.rowsAffected);
if (res.rowsAffected == 0)
tx.executeSql("Insert into test_table (numberdata)values(2)",[],function(tx1, res) {
if (i == 100) {
db.executeSql("Select Prime,NumberData from test_table;", [], function(res) {
self.postMessage('Final data: ' + res.rows.length.toString());
});
}
});
},function(error){
We were trying to use sqlite workers to move our transaction to worker thread. We observed that, when we use db.transcations multiple times on iOS, the memory usage shots up unprecedentaly and reached upto 350 MB for simple insert/update and a select query in the end. Here is a sample code which simulates the actual code.
`importScripts('SQLitePlugin.js');
self.addEventListener('message', function(ev) {
if (ev.data === 'go') {
var i = 0;
sqlitePlugin.openDatabase({
name: 'testdb.db'
}, function(db) {
db.executeSql("Select Max(Prime) lastItem from test_table;", [], function(res) {
var nextRow = res.rows.item(0).lastItem + 1;
do {
i++;
nextRow++;
db.transaction(function(tx) {
var next=nextRow;
tx.executeSql("Update test_table set numberdata=2 where prime=?",[next],function(tx1, res) {
self.postMessage('Rows affected: ' + res.rowsAffected);
if (res.rowsAffected == 0)
tx.executeSql("Insert into test_table (numberdata)values(2)",[],function(tx1, res) {
if (i == 100) {
db.executeSql("Select Prime,NumberData from test_table;", [], function(res) {
self.postMessage('Final data: ' + res.rows.length.toString());
});
}
});
},function(error){
Am I doing any thing wrong? Is there any better usage suggestions.
[testdb.db.zip](https://github.com/litehelpers/cordova-sqlite-workers-evfree/files/212943/testdb.db.zip)
The text was updated successfully, but these errors were encountered: