mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 11:56:01 +01:00
WIP blobs
This commit is contained in:
@@ -12,9 +12,9 @@ const becca = require("../../becca/becca");
|
||||
function getNoteRevisions(req) {
|
||||
return becca.getNoteRevisionsFromQuery(`
|
||||
SELECT note_revisions.*,
|
||||
LENGTH(note_revision_contents.content) AS contentLength
|
||||
LENGTH(blobs.content) AS contentLength
|
||||
FROM note_revisions
|
||||
JOIN note_revision_contents ON note_revisions.noteRevisionId = note_revision_contents.noteRevisionId
|
||||
JOIN blobs ON note_revisions.blobId = blobs.blobId
|
||||
WHERE noteId = ?
|
||||
ORDER BY utcDateCreated DESC`, [req.params.noteId]);
|
||||
}
|
||||
|
||||
@@ -4,18 +4,19 @@ const NotFoundError = require("../../errors/not_found_error");
|
||||
|
||||
function getNoteSize(req) {
|
||||
const {noteId} = req.params;
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
const noteSize = sql.getValue(`
|
||||
SELECT
|
||||
COALESCE((SELECT LENGTH(content) FROM note_contents WHERE noteId = ?), 0)
|
||||
COALESCE((SELECT LENGTH(content) FROM blobs WHERE blobId = ?), 0)
|
||||
+
|
||||
COALESCE(
|
||||
(SELECT SUM(LENGTH(content))
|
||||
FROM note_revisions
|
||||
JOIN note_revision_contents USING (noteRevisionId)
|
||||
JOIN blobs USING (blobId)
|
||||
WHERE note_revisions.noteId = ?),
|
||||
0
|
||||
)`, [noteId, noteId]);
|
||||
)`, [note.blobId, noteId]);
|
||||
|
||||
return {
|
||||
noteSize
|
||||
@@ -38,14 +39,15 @@ function getSubtreeSize(req) {
|
||||
SELECT
|
||||
COALESCE((
|
||||
SELECT SUM(LENGTH(content))
|
||||
FROM note_contents
|
||||
JOIN param_list ON param_list.paramId = note_contents.noteId
|
||||
FROM notes
|
||||
JOIN blobs USING (blobId)
|
||||
JOIN param_list ON param_list.paramId = notes.noteId
|
||||
), 0)
|
||||
+
|
||||
COALESCE(
|
||||
(SELECT SUM(LENGTH(content))
|
||||
FROM note_revisions
|
||||
JOIN note_revision_contents USING (noteRevisionId)
|
||||
JOIN blobs USING (blobId)
|
||||
JOIN param_list ON param_list.paramId = note_revisions.noteId),
|
||||
0
|
||||
)`);
|
||||
|
||||
@@ -12,6 +12,7 @@ const syncOptions = require('../../services/sync_options');
|
||||
const dateUtils = require('../../services/date_utils');
|
||||
const utils = require('../../services/utils');
|
||||
const ws = require('../../services/ws');
|
||||
const becca = require("../../becca/becca.js");
|
||||
|
||||
async function testSync() {
|
||||
try {
|
||||
@@ -85,14 +86,15 @@ function forceFullSync() {
|
||||
|
||||
function forceNoteSync(req) {
|
||||
const noteId = req.params.noteId;
|
||||
const note = becca.getNote(noteId);
|
||||
|
||||
const now = dateUtils.utcNowDateTime();
|
||||
|
||||
sql.execute(`UPDATE notes SET utcDateModified = ? WHERE noteId = ?`, [now, noteId]);
|
||||
entityChangesService.moveEntityChangeToTop('notes', noteId);
|
||||
|
||||
sql.execute(`UPDATE note_contents SET utcDateModified = ? WHERE noteId = ?`, [now, noteId]);
|
||||
entityChangesService.moveEntityChangeToTop('note_contents', noteId);
|
||||
sql.execute(`UPDATE blobs SET utcDateModified = ? WHERE blobId = ?`, [now, note.blobId]);
|
||||
entityChangesService.moveEntityChangeToTop('blobs', note.blobId);
|
||||
|
||||
for (const branchId of sql.getColumn("SELECT branchId FROM branches WHERE noteId = ?", [noteId])) {
|
||||
sql.execute(`UPDATE branches SET utcDateModified = ? WHERE branchId = ?`, [now, branchId]);
|
||||
@@ -109,17 +111,11 @@ function forceNoteSync(req) {
|
||||
for (const noteRevisionId of sql.getColumn("SELECT noteRevisionId FROM note_revisions WHERE noteId = ?", [noteId])) {
|
||||
sql.execute(`UPDATE note_revisions SET utcDateModified = ? WHERE noteRevisionId = ?`, [now, noteRevisionId]);
|
||||
entityChangesService.moveEntityChangeToTop('note_revisions', noteRevisionId);
|
||||
|
||||
sql.execute(`UPDATE note_revision_contents SET utcDateModified = ? WHERE noteRevisionId = ?`, [now, noteRevisionId]);
|
||||
entityChangesService.moveEntityChangeToTop('note_revision_contents', noteRevisionId);
|
||||
}
|
||||
|
||||
for (const noteAncillaryId of sql.getColumn("SELECT noteAncillaryId FROM note_ancillaries WHERE noteId = ?", [noteId])) {
|
||||
sql.execute(`UPDATE note_ancillaries SET utcDateModified = ? WHERE noteAncillaryId = ?`, [now, noteAncillaryId]);
|
||||
entityChangesService.moveEntityChangeToTop('note_ancillaries', noteAncillaryId);
|
||||
|
||||
sql.execute(`UPDATE note_ancillary_contents SET utcDateModified = ? WHERE noteAncillaryId = ?`, [now, noteAncillaryId]);
|
||||
entityChangesService.moveEntityChangeToTop('note_ancillary_contents', noteAncillaryId);
|
||||
}
|
||||
|
||||
log.info(`Forcing note sync for ${noteId}`);
|
||||
|
||||
Reference in New Issue
Block a user