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,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "trilium",
|
|
||||||
"version": "0.59.4",
|
"version": "0.59.4",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
|
@ -4,19 +4,18 @@ const NotFoundError = require("../../errors/not_found_error");
|
|||||||
|
|
||||||
function getNoteSize(req) {
|
function getNoteSize(req) {
|
||||||
const {noteId} = req.params;
|
const {noteId} = req.params;
|
||||||
const note = becca.getNote(noteId);
|
|
||||||
|
|
||||||
const noteSize = sql.getValue(`
|
const blobSizes = sql.getMap(`
|
||||||
SELECT
|
SELECT blobs.blobId, LENGTH(content)
|
||||||
COALESCE((SELECT LENGTH(content) FROM blobs WHERE blobId = ?), 0)
|
FROM blobs
|
||||||
+
|
LEFT JOIN notes ON notes.blobId = blobs.blobId AND notes.noteId = ? AND notes.isDeleted = 0
|
||||||
COALESCE(
|
LEFT JOIN attachments ON attachments.blobId = blobs.blobId AND attachments.parentId = ? AND attachments.isDeleted = 0
|
||||||
(SELECT SUM(LENGTH(content))
|
LEFT JOIN note_revisions ON note_revisions.blobId = blobs.blobId AND note_revisions.noteId = ?
|
||||||
FROM note_revisions
|
WHERE notes.noteId IS NOT NULL
|
||||||
JOIN blobs USING (blobId)
|
OR attachments.attachmentId IS NOT NULL
|
||||||
WHERE note_revisions.noteId = ?),
|
OR note_revisions.noteRevisionId IS NOT NULL`, [noteId, noteId, noteId]);
|
||||||
0
|
|
||||||
)`, [note.blobId, noteId]);
|
const noteSize = Object.values(blobSizes).reduce((acc, blobSize) => acc + blobSize, 0);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
noteSize
|
noteSize
|
||||||
@ -35,22 +34,15 @@ function getSubtreeSize(req) {
|
|||||||
|
|
||||||
sql.fillParamList(subTreeNoteIds);
|
sql.fillParamList(subTreeNoteIds);
|
||||||
|
|
||||||
const subTreeSize = sql.getValue(`
|
const blobSizes = sql.getMap(`
|
||||||
SELECT
|
SELECT blobs.blobId, LENGTH(content)
|
||||||
COALESCE((
|
FROM param_list
|
||||||
SELECT SUM(LENGTH(content))
|
JOIN notes ON notes.noteId = param_list.paramId AND notes.isDeleted = 0
|
||||||
FROM notes
|
LEFT JOIN attachments ON attachments.parentId = param_list.paramId AND attachments.isDeleted = 0
|
||||||
JOIN blobs USING (blobId)
|
LEFT JOIN note_revisions ON note_revisions.noteId = param_list.paramId
|
||||||
JOIN param_list ON param_list.paramId = notes.noteId
|
JOIN blobs ON blobs.blobId = notes.blobId OR blobs.blobId = attachments.blobId OR blobs.blobId = note_revisions.blobId`);
|
||||||
), 0)
|
|
||||||
+
|
const subTreeSize = Object.values(blobSizes).reduce((acc, blobSize) => acc + blobSize, 0);
|
||||||
COALESCE(
|
|
||||||
(SELECT SUM(LENGTH(content))
|
|
||||||
FROM note_revisions
|
|
||||||
JOIN blobs USING (blobId)
|
|
||||||
JOIN param_list ON param_list.paramId = note_revisions.noteId),
|
|
||||||
0
|
|
||||||
)`);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subTreeSize,
|
subTreeSize,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user