mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
recent changes respect hoisted note state
This commit is contained in:
parent
f8bd6183bf
commit
cc298b1e7a
@ -4,6 +4,7 @@ import server from '../services/server.js';
|
|||||||
import treeService from "../services/tree.js";
|
import treeService from "../services/tree.js";
|
||||||
import treeCache from "../services/tree_cache.js";
|
import treeCache from "../services/tree_cache.js";
|
||||||
import appContext from "../services/app_context.js";
|
import appContext from "../services/app_context.js";
|
||||||
|
import hoistedNoteService from "../services/hoisted_note.js";
|
||||||
|
|
||||||
const $dialog = $("#recent-changes-dialog");
|
const $dialog = $("#recent-changes-dialog");
|
||||||
const $content = $("#recent-changes-content");
|
const $content = $("#recent-changes-content");
|
||||||
@ -11,7 +12,7 @@ const $content = $("#recent-changes-content");
|
|||||||
export async function showDialog() {
|
export async function showDialog() {
|
||||||
utils.openDialog($dialog);
|
utils.openDialog($dialog);
|
||||||
|
|
||||||
const result = await server.get('recent-changes');
|
const result = await server.get('recent-changes/' + hoistedNoteService.getHoistedNoteId());
|
||||||
|
|
||||||
// preload all notes into cache
|
// preload all notes into cache
|
||||||
await treeCache.getNotes(result.map(r => r.noteId), true);
|
await treeCache.getNotes(result.map(r => r.noteId), true);
|
||||||
|
@ -3,45 +3,73 @@
|
|||||||
const sql = require('../../services/sql');
|
const sql = require('../../services/sql');
|
||||||
const protectedSessionService = require('../../services/protected_session');
|
const protectedSessionService = require('../../services/protected_session');
|
||||||
const noteService = require('../../services/notes');
|
const noteService = require('../../services/notes');
|
||||||
|
const noteCacheService = require('../../services/note_cache');
|
||||||
|
|
||||||
async function getRecentChanges() {
|
async function getRecentChanges(req) {
|
||||||
const recentChanges = await sql.getRows(
|
const {ancestorNoteId} = req.params;
|
||||||
|
|
||||||
|
const noteRows = await sql.getRows(
|
||||||
`
|
`
|
||||||
SELECT * FROM (
|
SELECT * FROM (
|
||||||
SELECT
|
SELECT note_revisions.noteId,
|
||||||
notes.noteId,
|
note_revisions.noteRevisionId,
|
||||||
notes.isDeleted AS current_isDeleted,
|
note_revisions.utcDateCreated AS date
|
||||||
notes.deleteId AS current_deleteId,
|
FROM note_revisions
|
||||||
notes.isErased AS current_isErased,
|
ORDER BY note_revisions.utcDateCreated DESC
|
||||||
notes.title AS current_title,
|
|
||||||
notes.isProtected AS current_isProtected,
|
|
||||||
note_revisions.title,
|
|
||||||
note_revisions.utcDateCreated AS date
|
|
||||||
FROM
|
|
||||||
note_revisions
|
|
||||||
JOIN notes USING(noteId)
|
|
||||||
ORDER BY
|
|
||||||
note_revisions.utcDateCreated DESC
|
|
||||||
LIMIT 200
|
|
||||||
)
|
)
|
||||||
UNION ALL SELECT * FROM (
|
UNION ALL SELECT * FROM (
|
||||||
SELECT
|
SELECT
|
||||||
notes.noteId,
|
notes.noteId,
|
||||||
notes.isDeleted AS current_isDeleted,
|
NULL AS noteRevisionId,
|
||||||
notes.deleteId AS current_deleteId,
|
utcDateModified AS date
|
||||||
notes.isErased AS current_isErased,
|
FROM notes
|
||||||
notes.title AS current_title,
|
ORDER BY utcDateModified DESC
|
||||||
notes.isProtected AS current_isProtected,
|
|
||||||
notes.title,
|
|
||||||
notes.utcDateModified AS date
|
|
||||||
FROM
|
|
||||||
notes
|
|
||||||
ORDER BY
|
|
||||||
utcDateModified DESC
|
|
||||||
LIMIT 200
|
|
||||||
)
|
)
|
||||||
ORDER BY date DESC
|
ORDER BY date DESC`);
|
||||||
LIMIT 200`);
|
|
||||||
|
const recentChanges = [];
|
||||||
|
|
||||||
|
for (const noteRow of noteRows) {
|
||||||
|
if (!noteCacheService.isInAncestor(noteRow.noteId, ancestorNoteId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (noteRow.noteRevisionId) {
|
||||||
|
recentChanges.push(await sql.getRow(`
|
||||||
|
SELECT
|
||||||
|
notes.noteId,
|
||||||
|
notes.isDeleted AS current_isDeleted,
|
||||||
|
notes.deleteId AS current_deleteId,
|
||||||
|
notes.isErased AS current_isErased,
|
||||||
|
notes.title AS current_title,
|
||||||
|
notes.isProtected AS current_isProtected,
|
||||||
|
note_revisions.title,
|
||||||
|
note_revisions.utcDateCreated AS date
|
||||||
|
FROM
|
||||||
|
note_revisions
|
||||||
|
JOIN notes USING(noteId)
|
||||||
|
WHERE noteRevisionId = ?`, [noteRow.noteRevisionId]));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
recentChanges.push(await sql.getRow(`
|
||||||
|
SELECT
|
||||||
|
notes.noteId,
|
||||||
|
notes.isDeleted AS current_isDeleted,
|
||||||
|
notes.deleteId AS current_deleteId,
|
||||||
|
notes.isErased AS current_isErased,
|
||||||
|
notes.title AS current_title,
|
||||||
|
notes.isProtected AS current_isProtected,
|
||||||
|
notes.title,
|
||||||
|
notes.utcDateModified AS date
|
||||||
|
FROM
|
||||||
|
notes
|
||||||
|
WHERE noteId = ?`, [noteRow.noteId]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recentChanges.length >= 200) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const change of recentChanges) {
|
for (const change of recentChanges) {
|
||||||
if (change.current_isProtected) {
|
if (change.current_isProtected) {
|
||||||
|
@ -181,7 +181,7 @@ function register(app) {
|
|||||||
route(POST, '/api/images', [auth.checkApiAuthOrElectron, uploadMiddleware, csrfMiddleware], imageRoute.uploadImage, apiResultHandler);
|
route(POST, '/api/images', [auth.checkApiAuthOrElectron, uploadMiddleware, csrfMiddleware], imageRoute.uploadImage, apiResultHandler);
|
||||||
route(PUT, '/api/images/:noteId', [auth.checkApiAuthOrElectron, uploadMiddleware, csrfMiddleware], imageRoute.updateImage, apiResultHandler);
|
route(PUT, '/api/images/:noteId', [auth.checkApiAuthOrElectron, uploadMiddleware, csrfMiddleware], imageRoute.updateImage, apiResultHandler);
|
||||||
|
|
||||||
apiRoute(GET, '/api/recent-changes', recentChangesApiRoute.getRecentChanges);
|
apiRoute(GET, '/api/recent-changes/:ancestorNoteId', recentChangesApiRoute.getRecentChanges);
|
||||||
|
|
||||||
apiRoute(GET, '/api/options', optionsApiRoute.getOptions);
|
apiRoute(GET, '/api/options', optionsApiRoute.getOptions);
|
||||||
// FIXME: possibly change to sending value in the body to avoid host of HTTP server issues with slashes
|
// FIXME: possibly change to sending value in the body to avoid host of HTTP server issues with slashes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user