mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 02:45:54 +01:00
optional cleanup of unused images
This commit is contained in:
@@ -22,6 +22,10 @@ router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, wrap(async (req, r
|
||||
|
||||
await sql.execute("DELETE FROM notes_tree WHERE is_deleted = 1");
|
||||
|
||||
await sql.execute("DELETE FROM notes_image WHERE is_deleted = 1");
|
||||
|
||||
await sql.execute("DELETE FROM images WHERE is_deleted = 1");
|
||||
|
||||
await sql.execute("DELETE FROM notes WHERE is_deleted = 1");
|
||||
|
||||
await sql.execute("DELETE FROM recent_notes");
|
||||
@@ -37,6 +41,33 @@ router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, wrap(async (req, r
|
||||
res.send({});
|
||||
}));
|
||||
|
||||
router.post('/cleanup-unused-images', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const sourceId = req.headers.source_id;
|
||||
|
||||
await sql.doInTransaction(async () => {
|
||||
const unusedImageIds = await sql.getFirstColumn(`
|
||||
SELECT images.image_id
|
||||
FROM images
|
||||
LEFT JOIN notes_image ON notes_image.image_id = images.image_id AND notes_image.is_deleted = 0
|
||||
WHERE
|
||||
images.is_deleted = 0
|
||||
AND notes_image.note_image_id IS NULL`);
|
||||
|
||||
const now = utils.nowDate();
|
||||
|
||||
for (const imageId of unusedImageIds) {
|
||||
log.info(`Deleting unused image: ${imageId}`);
|
||||
|
||||
await sql.execute("UPDATE images SET is_deleted = 1, data = null, date_modified = ? WHERE image_id = ?",
|
||||
[now, imageId]);
|
||||
|
||||
await sync_table.addImageSync(imageId, sourceId);
|
||||
}
|
||||
});
|
||||
|
||||
res.send({});
|
||||
}));
|
||||
|
||||
router.post('/vacuum-database', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
await sql.execute("VACUUM");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user