mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fix note size calculation with blobs
This commit is contained in:
parent
8edf06d28d
commit
78d83b8826
1
package-lock.json
generated
1
package-lock.json
generated
@ -5,7 +5,6 @@
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "trilium",
|
||||
"version": "0.59.4",
|
||||
"hasInstallScript": true,
|
||||
"license": "AGPL-3.0-only",
|
||||
|
@ -4,19 +4,18 @@ 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 blobs WHERE blobId = ?), 0)
|
||||
+
|
||||
COALESCE(
|
||||
(SELECT SUM(LENGTH(content))
|
||||
FROM note_revisions
|
||||
JOIN blobs USING (blobId)
|
||||
WHERE note_revisions.noteId = ?),
|
||||
0
|
||||
)`, [note.blobId, noteId]);
|
||||
const blobSizes = sql.getMap(`
|
||||
SELECT blobs.blobId, LENGTH(content)
|
||||
FROM blobs
|
||||
LEFT JOIN notes ON notes.blobId = blobs.blobId AND notes.noteId = ? AND notes.isDeleted = 0
|
||||
LEFT JOIN attachments ON attachments.blobId = blobs.blobId AND attachments.parentId = ? AND attachments.isDeleted = 0
|
||||
LEFT JOIN note_revisions ON note_revisions.blobId = blobs.blobId AND note_revisions.noteId = ?
|
||||
WHERE notes.noteId IS NOT NULL
|
||||
OR attachments.attachmentId IS NOT NULL
|
||||
OR note_revisions.noteRevisionId IS NOT NULL`, [noteId, noteId, noteId]);
|
||||
|
||||
const noteSize = Object.values(blobSizes).reduce((acc, blobSize) => acc + blobSize, 0);
|
||||
|
||||
return {
|
||||
noteSize
|
||||
@ -35,22 +34,15 @@ function getSubtreeSize(req) {
|
||||
|
||||
sql.fillParamList(subTreeNoteIds);
|
||||
|
||||
const subTreeSize = sql.getValue(`
|
||||
SELECT
|
||||
COALESCE((
|
||||
SELECT SUM(LENGTH(content))
|
||||
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 blobs USING (blobId)
|
||||
JOIN param_list ON param_list.paramId = note_revisions.noteId),
|
||||
0
|
||||
)`);
|
||||
const blobSizes = sql.getMap(`
|
||||
SELECT blobs.blobId, LENGTH(content)
|
||||
FROM param_list
|
||||
JOIN notes ON notes.noteId = param_list.paramId AND notes.isDeleted = 0
|
||||
LEFT JOIN attachments ON attachments.parentId = param_list.paramId AND attachments.isDeleted = 0
|
||||
LEFT JOIN note_revisions ON note_revisions.noteId = param_list.paramId
|
||||
JOIN blobs ON blobs.blobId = notes.blobId OR blobs.blobId = attachments.blobId OR blobs.blobId = note_revisions.blobId`);
|
||||
|
||||
const subTreeSize = Object.values(blobSizes).reduce((acc, blobSize) => acc + blobSize, 0);
|
||||
|
||||
return {
|
||||
subTreeSize,
|
||||
|
Loading…
x
Reference in New Issue
Block a user