mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 11:26:15 +01:00
cleanup of soft deleted items
vacuuming database consolidation of "advanced" operations in settings
This commit is contained in:
43
routes/api/cleanup.js
Normal file
43
routes/api/cleanup.js
Normal file
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const sql = require('../../services/sql');
|
||||
const utils = require('../../services/utils');
|
||||
const sync_table = require('../../services/sync_table');
|
||||
|
||||
router.post('/cleanup-soft-deleted-items', async (req, res, next) => {
|
||||
await sql.doInTransaction(async () => {
|
||||
const noteIdsToDelete = await sql.getFlattenedResults("SELECT note_id FROM notes WHERE is_deleted = 1");
|
||||
const noteIdsSql = noteIdsToDelete
|
||||
.map(noteId => "'" + utils.sanitizeSql(noteId) + "'")
|
||||
.join(', ');
|
||||
|
||||
console.log("Note IDS for deletion", noteIdsSql);
|
||||
|
||||
await sql.execute(`DELETE FROM event_log WHERE note_id IN (${noteIdsSql})`);
|
||||
|
||||
await sql.execute(`DELETE FROM notes_history WHERE note_id IN (${noteIdsSql})`);
|
||||
|
||||
await sql.execute("DELETE FROM notes_tree WHERE is_deleted = 1");
|
||||
|
||||
await sql.execute("DELETE FROM notes WHERE is_deleted = 1");
|
||||
|
||||
await sql.execute("DELETE FROM recent_notes");
|
||||
|
||||
await sync_table.cleanupSyncRowsForMissingEntities("notes", "note_id");
|
||||
await sync_table.cleanupSyncRowsForMissingEntities("notes_tree", "note_tree_id");
|
||||
await sync_table.cleanupSyncRowsForMissingEntities("notes_history", "note_history_id");
|
||||
await sync_table.cleanupSyncRowsForMissingEntities("recent_notes", "note_tree_id");
|
||||
});
|
||||
|
||||
res.send({});
|
||||
});
|
||||
|
||||
router.post('/vacuum-database', async (req, res, next) => {
|
||||
await sql.execute("VACUUM");
|
||||
|
||||
res.send({});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user