smaller refactorings (mostly entitization)

This commit is contained in:
azivner
2018-04-01 11:05:09 -04:00
parent c9d73c6115
commit fad0ec757b
12 changed files with 69 additions and 56 deletions

View File

@@ -4,6 +4,7 @@ const sql = require('../../services/sql');
const utils = require('../../services/utils');
const sync_table = require('../../services/sync_table');
const log = require('../../services/log');
const repository = require('../../services/repository');
async function cleanupSoftDeletedItems() {
const noteIdsToDelete = await sql.getColumn("SELECT noteId FROM notes WHERE isDeleted = 1");
@@ -33,6 +34,9 @@ async function cleanupSoftDeletedItems() {
await sync_table.cleanupSyncRowsForMissingEntities("branches", "branchId");
await sync_table.cleanupSyncRowsForMissingEntities("note_revisions", "noteRevisionId");
await sync_table.cleanupSyncRowsForMissingEntities("recent_notes", "branchId");
await sync_table.cleanupSyncRowsForMissingEntities("images", "imageId");
await sync_table.cleanupSyncRowsForMissingEntities("note_images", "noteImageId");
await sync_table.cleanupSyncRowsForMissingEntities("labels", "labelId");
log.info("Following notes has been completely cleaned from database: " + noteIdsSql);
}
@@ -51,10 +55,10 @@ async function cleanupUnusedImages() {
for (const imageId of unusedImageIds) {
log.info(`Deleting unused image: ${imageId}`);
await sql.execute("UPDATE images SET isDeleted = 1, data = null, dateModified = ? WHERE imageId = ?",
[now, imageId]);
await sync_table.addImageSync(imageId);
const image = await repository.getImage(imageId);
image.isDeleted = true;
image.data = null;
await image.save();
}
}