mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
WIP for counting note and subtree size
This commit is contained in:
parent
d67e1552ee
commit
200982655f
@ -1,4 +1,5 @@
|
|||||||
import CollapsibleWidget from "../collapsible_widget.js";
|
import CollapsibleWidget from "../collapsible_widget.js";
|
||||||
|
import server from "../../services/server.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<table class="note-info-widget-table">
|
<table class="note-info-widget-table">
|
||||||
@ -78,6 +79,14 @@ export default class NoteInfoWidget extends CollapsibleWidget {
|
|||||||
else {
|
else {
|
||||||
this.$mime.empty();
|
this.$mime.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let resp = await server.get(`stats/note-size/${note.noteId}`);
|
||||||
|
|
||||||
|
console.log(resp);
|
||||||
|
|
||||||
|
resp = await server.get(`stats/subtree-size/${note.noteId}`);
|
||||||
|
|
||||||
|
console.log(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
entitiesReloadedEvent({loadResults}) {
|
entitiesReloadedEvent({loadResults}) {
|
||||||
|
60
src/routes/api/stats.js
Normal file
60
src/routes/api/stats.js
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
const sql = require('../../services/sql');
|
||||||
|
const noteCache = require('../../services/note_cache/note_cache');
|
||||||
|
|
||||||
|
function getNoteSize(req) {
|
||||||
|
const {noteId} = req.params;
|
||||||
|
|
||||||
|
const noteSize = sql.getValue(`
|
||||||
|
SELECT
|
||||||
|
COALESCE((SELECT LENGTH(content) FROM note_contents WHERE noteId = ?), 0)
|
||||||
|
+
|
||||||
|
COALESCE(
|
||||||
|
(SELECT SUM(LENGTH(content))
|
||||||
|
FROM note_revisions
|
||||||
|
JOIN note_revision_contents USING (noteRevisionId)
|
||||||
|
WHERE note_revisions.noteId = ?),
|
||||||
|
0
|
||||||
|
)`, [noteId, noteId]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
noteSize
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSubtreeSize(req) {
|
||||||
|
const {noteId} = req.params;
|
||||||
|
const note = noteCache.notes[noteId];
|
||||||
|
|
||||||
|
if (!note) {
|
||||||
|
return [404, `Note ${noteId} was not found.`];
|
||||||
|
}
|
||||||
|
|
||||||
|
const subTreeNoteIds = note.subtreeNotes.map(note => note.noteId);
|
||||||
|
|
||||||
|
sql.fillNoteIdList(subTreeNoteIds);
|
||||||
|
|
||||||
|
const subTreeSize = sql.getValue(`
|
||||||
|
SELECT
|
||||||
|
COALESCE((
|
||||||
|
SELECT SUM(LENGTH(content))
|
||||||
|
FROM note_contents
|
||||||
|
JOIN param_list ON param_list.paramId = note_contents.noteId
|
||||||
|
), 0)
|
||||||
|
+
|
||||||
|
COALESCE(
|
||||||
|
(SELECT SUM(LENGTH(content))
|
||||||
|
FROM note_revisions
|
||||||
|
JOIN note_revision_contents USING (noteRevisionId)
|
||||||
|
JOIN param_list ON param_list.paramId = note_revisions.noteId),
|
||||||
|
0
|
||||||
|
)`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
subTreeSize
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getNoteSize,
|
||||||
|
getSubtreeSize
|
||||||
|
};
|
@ -37,6 +37,7 @@ const clipperRoute = require('./api/clipper');
|
|||||||
const similarNotesRoute = require('./api/similar_notes');
|
const similarNotesRoute = require('./api/similar_notes');
|
||||||
const keysRoute = require('./api/keys');
|
const keysRoute = require('./api/keys');
|
||||||
const backendLogRoute = require('./api/backend_log');
|
const backendLogRoute = require('./api/backend_log');
|
||||||
|
const statsRoute = require('./api/stats');
|
||||||
|
|
||||||
const log = require('../services/log');
|
const log = require('../services/log');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
@ -280,6 +281,9 @@ function register(app) {
|
|||||||
|
|
||||||
apiRoute(GET, '/api/backend-log', backendLogRoute.getBackendLog);
|
apiRoute(GET, '/api/backend-log', backendLogRoute.getBackendLog);
|
||||||
|
|
||||||
|
apiRoute(GET, '/api/stats/note-size/:noteId', statsRoute.getNoteSize);
|
||||||
|
apiRoute(GET, '/api/stats/subtree-size/:noteId', statsRoute.getSubtreeSize);
|
||||||
|
|
||||||
app.use('', router);
|
app.use('', router);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user