mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fix calculating revision attachment size
This commit is contained in:
parent
055bb39e4d
commit
9db0a062ed
@ -92,6 +92,13 @@ function searchFromRelation(note, relationName) {
|
||||
function loadNeededInfoFromDatabase() {
|
||||
const sql = require('../../sql');
|
||||
|
||||
/**
|
||||
* This complex structure is needed to calculate total occupied space by a note. Several object instances
|
||||
* (note, revisions, attachments) can point to a single blobId, and thus the blob size should count towards the total
|
||||
* only once.
|
||||
*
|
||||
* @var {Object.<string, Object.<string, int>>} - noteId => { blobId => blobSize }
|
||||
*/
|
||||
const noteBlobs = {};
|
||||
|
||||
const noteContentLengths = sql.getRows(`
|
||||
@ -145,16 +152,28 @@ function loadNeededInfoFromDatabase() {
|
||||
}
|
||||
|
||||
const revisionContentLengths = sql.getRows(`
|
||||
SELECT
|
||||
noteId,
|
||||
revisions.blobId,
|
||||
LENGTH(content) AS length
|
||||
FROM notes
|
||||
JOIN revisions USING(noteId)
|
||||
JOIN blobs ON revisions.blobId = blobs.blobId
|
||||
WHERE notes.isDeleted = 0`);
|
||||
SELECT
|
||||
noteId,
|
||||
revisions.blobId,
|
||||
LENGTH(content) AS length,
|
||||
1 AS isNoteRevision
|
||||
FROM notes
|
||||
JOIN revisions USING(noteId)
|
||||
JOIN blobs ON revisions.blobId = blobs.blobId
|
||||
WHERE notes.isDeleted = 0
|
||||
UNION ALL
|
||||
SELECT
|
||||
noteId,
|
||||
revisions.blobId,
|
||||
LENGTH(content) AS length,
|
||||
0 AS isNoteRevision -- it's attachment not counting towards revision count
|
||||
FROM notes
|
||||
JOIN revisions USING(noteId)
|
||||
JOIN attachments ON attachments.ownerId = revisions.revisionId
|
||||
JOIN blobs ON attachments.blobId = blobs.blobId
|
||||
WHERE notes.isDeleted = 0`);
|
||||
|
||||
for (const {noteId, blobId, length} of revisionContentLengths) {
|
||||
for (const {noteId, blobId, length, isNoteRevision} of revisionContentLengths) {
|
||||
if (!(noteId in becca.notes)) {
|
||||
log.error(`Note '${noteId}' not found in becca.`);
|
||||
continue;
|
||||
@ -167,7 +186,9 @@ function loadNeededInfoFromDatabase() {
|
||||
|
||||
noteBlobs[noteId][blobId] = length;
|
||||
|
||||
becca.notes[noteId].revisionCount++;
|
||||
if (isNoteRevision) {
|
||||
becca.notes[noteId].revisionCount++;
|
||||
}
|
||||
}
|
||||
|
||||
for (const noteId in noteBlobs) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user