1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-30 23:44:55 +02:00

All: Handle deletion of resources that are not linked to any note

This commit is contained in:
Laurent Cozic
2018-03-16 17:39:44 +00:00
parent f81dbf4a4c
commit 544f93bf22
8 changed files with 80 additions and 34 deletions

@ -3,14 +3,13 @@ const { promiseChain } = require('lib/promise-utils.js');
const { Logger } = require('lib/logger.js');
const { time } = require('lib/time-utils.js');
const { sprintf } = require('sprintf-js');
const Mutex = require('async-mutex').Mutex;
class Database {
constructor(driver) {
this.debugMode_ = false;
this.driver_ = driver;
this.inTransaction_ = false;
this.logger_ = new Logger();
this.logExcludedQueryTypes_ = [];
}
@ -113,29 +112,20 @@ class Database {
return;
}
// There can be only one transaction running at a time so queue
// any new transaction here.
if (this.inTransaction_) {
while (true) {
await time.msleep(100);
if (!this.inTransaction_) {
this.inTransaction_ = true;
break;
}
// There can be only one transaction running at a time so use a mutex
const release = await Database.batchTransactionMutex_.acquire();
try {
queries.splice(0, 0, 'BEGIN TRANSACTION');
queries.push('COMMIT'); // Note: ROLLBACK is currently not supported
for (let i = 0; i < queries.length; i++) {
let query = this.wrapQuery(queries[i]);
await this.exec(query.sql, query.params);
}
} finally {
release();
}
this.inTransaction_ = true;
queries.splice(0, 0, 'BEGIN TRANSACTION');
queries.push('COMMIT'); // Note: ROLLBACK is currently not supported
for (let i = 0; i < queries.length; i++) {
let query = this.wrapQuery(queries[i]);
await this.exec(query.sql, query.params);
}
this.inTransaction_ = false;
}
static enumId(type, s) {
@ -310,6 +300,8 @@ class Database {
}
Database.batchTransactionMutex_ = new Mutex();
Database.TYPE_UNKNOWN = 0;
Database.TYPE_INT = 1;
Database.TYPE_TEXT = 2;