mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 10:40:41 +01:00
smaller refactorings (mostly entitization)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ const sql = require('../../services/sql');
|
||||
const utils = require('../../services/utils');
|
||||
const sync_table = require('../../services/sync_table');
|
||||
const tree = require('../../services/tree');
|
||||
const Branch = require('../../entities/branch');
|
||||
|
||||
async function cloneNoteToParent(req) {
|
||||
const parentNoteId = req.params.parentNoteId;
|
||||
@@ -19,7 +20,7 @@ async function cloneNoteToParent(req) {
|
||||
const maxNotePos = await sql.getValue('SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0', [parentNoteId]);
|
||||
const newNotePos = maxNotePos === null ? 0 : maxNotePos + 1;
|
||||
|
||||
const branch = {
|
||||
const branch = new Branch({
|
||||
branchId: utils.newBranchId(),
|
||||
noteId: childNoteId,
|
||||
parentNoteId: parentNoteId,
|
||||
@@ -28,11 +29,9 @@ async function cloneNoteToParent(req) {
|
||||
isExpanded: 0,
|
||||
dateModified: utils.nowDate(),
|
||||
isDeleted: 0
|
||||
};
|
||||
});
|
||||
|
||||
await sql.replace("branches", branch);
|
||||
|
||||
await sync_table.addBranchSync(branch.branchId);
|
||||
await branch.save();
|
||||
|
||||
await sql.execute("UPDATE branches SET isExpanded = 1 WHERE noteId = ?", [parentNoteId]);
|
||||
|
||||
@@ -58,7 +57,7 @@ async function cloneNoteAfter(req) {
|
||||
|
||||
await sync_table.addNoteReorderingSync(afterNote.parentNoteId);
|
||||
|
||||
const branch = {
|
||||
const branch = new Branch({
|
||||
branchId: utils.newBranchId(),
|
||||
noteId: noteId,
|
||||
parentNoteId: afterNote.parentNoteId,
|
||||
@@ -66,11 +65,9 @@ async function cloneNoteAfter(req) {
|
||||
isExpanded: 0,
|
||||
dateModified: utils.nowDate(),
|
||||
isDeleted: 0
|
||||
};
|
||||
});
|
||||
|
||||
await sql.replace("branches", branch);
|
||||
|
||||
await sync_table.addBranchSync(branch.branchId);
|
||||
await branch.save();
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
@@ -12,9 +12,7 @@ async function deleteOld() {
|
||||
const cutoffId = await sql.getValue("SELECT id FROM event_log ORDER BY id DESC LIMIT 1000, 1");
|
||||
|
||||
if (cutoffId) {
|
||||
await sql.doInTransaction(async () => {
|
||||
await sql.execute("DELETE FROM event_log WHERE id < ?", [cutoffId]);
|
||||
});
|
||||
await sql.execute("DELETE FROM event_log WHERE id < ?", [cutoffId]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ async function exportNote(req, res) {
|
||||
}
|
||||
|
||||
async function exportNoteInner(branchId, directory, pack) {
|
||||
const branch = await sql.getRow("SELECT * FROM branches WHERE branchId = ?", [branchId]);
|
||||
const note = await repository.getEntity("SELECT notes.* FROM notes WHERE noteId = ?", [branch.noteId]);
|
||||
const branch = await repository.getBranch(branchId);
|
||||
const note = await branch.getNote();
|
||||
|
||||
if (note.isProtected) {
|
||||
return;
|
||||
@@ -46,12 +46,8 @@ async function exportNoteInner(branchId, directory, pack) {
|
||||
|
||||
pack.entry({ name: childFileName + ".dat", size: content.length }, content);
|
||||
|
||||
const children = await sql.getRows("SELECT * FROM branches WHERE parentNoteId = ? AND isDeleted = 0", [note.noteId]);
|
||||
|
||||
if (children.length > 0) {
|
||||
for (const child of children) {
|
||||
await exportNoteInner(child.branchId, childFileName + "/", pack);
|
||||
}
|
||||
for (const child of await note.getChildBranches()) {
|
||||
await exportNoteInner(child.branchId, childFileName + "/", pack);
|
||||
}
|
||||
|
||||
return childFileName;
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
const sql = require('../../services/sql');
|
||||
const protected_session = require('../../services/protected_session');
|
||||
const repository = require('../../services/repository');
|
||||
|
||||
async function getNoteRevisions(req) {
|
||||
const noteId = req.params.noteId;
|
||||
const revisions = await sql.getRows("SELECT * FROM note_revisions WHERE noteId = ? order by dateModifiedTo desc", [noteId]);
|
||||
protected_session.decryptNoteRevisions(revisions);
|
||||
|
||||
return revisions;
|
||||
return await repository.getEntities("SELECT * FROM note_revisions WHERE noteId = ? order by dateModifiedTo desc", [noteId]);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -5,9 +5,9 @@ const options = require('../../services/options');
|
||||
const utils = require('../../services/utils');
|
||||
const config = require('../../services/config');
|
||||
const protected_session = require('../../services/protected_session');
|
||||
const sync_table = require('../../services/sync_table');
|
||||
const repository = require('../../services/repository');
|
||||
|
||||
async function getTree(req) {
|
||||
async function getTree() {
|
||||
const branches = await sql.getRows(`
|
||||
SELECT
|
||||
branchId,
|
||||
@@ -64,13 +64,9 @@ async function setPrefix(req) {
|
||||
const branchId = req.params.branchId;
|
||||
const prefix = utils.isEmptyOrWhitespace(req.body.prefix) ? null : req.body.prefix;
|
||||
|
||||
await sql.doInTransaction(async () => {
|
||||
await sql.execute("UPDATE branches SET prefix = ?, dateModified = ? WHERE branchId = ?", [prefix, utils.nowDate(), branchId]);
|
||||
|
||||
await sync_table.addBranchSync(branchId);
|
||||
});
|
||||
|
||||
return {};
|
||||
const branch = await repository.getBranch(branchId);
|
||||
branch.prefix = prefix;
|
||||
await branch.save();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user