mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	removed dangerous and unnecessary option to completely remove soft-deleted items
This commit is contained in:
		@@ -1,46 +1,9 @@
 | 
				
			|||||||
"use strict";
 | 
					"use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const sql = require('../../services/sql');
 | 
					const sql = require('../../services/sql');
 | 
				
			||||||
const utils = require('../../services/utils');
 | 
					 | 
				
			||||||
const syncTable = require('../../services/sync_table');
 | 
					 | 
				
			||||||
const log = require('../../services/log');
 | 
					const log = require('../../services/log');
 | 
				
			||||||
const repository = require('../../services/repository');
 | 
					const repository = require('../../services/repository');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function cleanupSoftDeletedItems() {
 | 
					 | 
				
			||||||
    const noteIdsToDelete = await sql.getColumn("SELECT noteId FROM notes WHERE isDeleted = 1");
 | 
					 | 
				
			||||||
    const noteIdsSql = noteIdsToDelete
 | 
					 | 
				
			||||||
        .map(noteId => "'" + utils.sanitizeSql(noteId) + "'")
 | 
					 | 
				
			||||||
        .join(', ');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await sql.execute(`DELETE FROM event_log WHERE noteId IN (${noteIdsSql})`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await sql.execute(`DELETE FROM note_revisions WHERE noteId IN (${noteIdsSql})`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await sql.execute(`DELETE FROM note_images WHERE noteId IN (${noteIdsSql})`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await sql.execute(`DELETE FROM labels WHERE noteId IN (${noteIdsSql})`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await sql.execute("DELETE FROM branches WHERE isDeleted = 1");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await sql.execute("DELETE FROM note_images WHERE isDeleted = 1");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await sql.execute("DELETE FROM images WHERE isDeleted = 1");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await sql.execute("DELETE FROM notes WHERE isDeleted = 1");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await sql.execute("DELETE FROM recent_notes");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await syncTable.cleanupSyncRowsForMissingEntities("notes", "noteId");
 | 
					 | 
				
			||||||
    await syncTable.cleanupSyncRowsForMissingEntities("branches", "branchId");
 | 
					 | 
				
			||||||
    await syncTable.cleanupSyncRowsForMissingEntities("note_revisions", "noteRevisionId");
 | 
					 | 
				
			||||||
    await syncTable.cleanupSyncRowsForMissingEntities("recent_notes", "branchId");
 | 
					 | 
				
			||||||
    await syncTable.cleanupSyncRowsForMissingEntities("images", "imageId");
 | 
					 | 
				
			||||||
    await syncTable.cleanupSyncRowsForMissingEntities("note_images", "noteImageId");
 | 
					 | 
				
			||||||
    await syncTable.cleanupSyncRowsForMissingEntities("labels", "labelId");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    log.info("Following notes has been completely cleaned from database: " + noteIdsSql);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
async function cleanupUnusedImages() {
 | 
					async function cleanupUnusedImages() {
 | 
				
			||||||
    const unusedImageIds = await sql.getColumn(`
 | 
					    const unusedImageIds = await sql.getColumn(`
 | 
				
			||||||
      SELECT images.imageId 
 | 
					      SELECT images.imageId 
 | 
				
			||||||
@@ -67,7 +30,6 @@ async function vacuumDatabase() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = {
 | 
					module.exports = {
 | 
				
			||||||
    cleanupSoftDeletedItems,
 | 
					 | 
				
			||||||
    cleanupUnusedImages,
 | 
					    cleanupUnusedImages,
 | 
				
			||||||
    vacuumDatabase
 | 
					    vacuumDatabase
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@@ -174,7 +174,6 @@ function register(app) {
 | 
				
			|||||||
    apiRoute(POST, '/api/sql/execute', sqlRoute.execute);
 | 
					    apiRoute(POST, '/api/sql/execute', sqlRoute.execute);
 | 
				
			||||||
    apiRoute(POST, '/api/anonymization/anonymize', anonymizationRoute.anonymize);
 | 
					    apiRoute(POST, '/api/anonymization/anonymize', anonymizationRoute.anonymize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    apiRoute(POST, '/api/cleanup/cleanup-soft-deleted-items', cleanupRoute.cleanupSoftDeletedItems);
 | 
					 | 
				
			||||||
    apiRoute(POST, '/api/cleanup/cleanup-unused-images', cleanupRoute.cleanupUnusedImages);
 | 
					    apiRoute(POST, '/api/cleanup/cleanup-unused-images', cleanupRoute.cleanupUnusedImages);
 | 
				
			||||||
    apiRoute(POST, '/api/cleanup/vacuum-database', cleanupRoute.vacuumDatabase);
 | 
					    apiRoute(POST, '/api/cleanup/vacuum-database', cleanupRoute.vacuumDatabase);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -461,14 +461,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            This means that some images can disappear from note revisions.</p>
 | 
					            This means that some images can disappear from note revisions.</p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          <button id="cleanup-unused-images-button" class="btn btn-warning btn-sm">Permanently cleanup unused images</button>
 | 
					          <button id="cleanup-unused-images-button" class="btn btn-sm">Permanently cleanup unused images</button>
 | 
				
			||||||
 | 
					 | 
				
			||||||
          <h4>Soft-delete cleanup</h4>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          <p>This deletes all soft deleted rows from the database. This change isn't synced and should be done manually on all instances.
 | 
					 | 
				
			||||||
            <strong>Use this only if you really know what you're doing.</strong></p>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          <button id="cleanup-soft-deleted-items-button" class="btn btn-danger btn-sm">Permanently cleanup soft-deleted items</button>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
          <h4>Vacuum database</h4>
 | 
					          <h4>Vacuum database</h4>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user