mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
recent changes sorting fixes, closes #1099
This commit is contained in:
parent
85d986534d
commit
9791dab97d
@ -16,18 +16,18 @@ export async function showDialog(ancestorNoteId) {
|
|||||||
ancestorNoteId = hoistedNoteService.getHoistedNoteId();
|
ancestorNoteId = hoistedNoteService.getHoistedNoteId();
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await server.get('recent-changes/' + ancestorNoteId);
|
const recentChangesRows = await server.get('recent-changes/' + ancestorNoteId);
|
||||||
|
|
||||||
// preload all notes into cache
|
// preload all notes into cache
|
||||||
await treeCache.getNotes(result.map(r => r.noteId), true);
|
await treeCache.getNotes(recentChangesRows.map(r => r.noteId), true);
|
||||||
|
|
||||||
$content.empty();
|
$content.empty();
|
||||||
|
|
||||||
if (result.length === 0) {
|
if (recentChangesRows.length === 0) {
|
||||||
$content.append("No changes yet ...");
|
$content.append("No changes yet ...");
|
||||||
}
|
}
|
||||||
|
|
||||||
const groupedByDate = groupByDate(result);
|
const groupedByDate = groupByDate(recentChangesRows);
|
||||||
|
|
||||||
for (const [dateDay, dayChanges] of groupedByDate) {
|
for (const [dateDay, dayChanges] of groupedByDate) {
|
||||||
const $changesList = $('<ul>');
|
const $changesList = $('<ul>');
|
||||||
@ -95,10 +95,10 @@ export async function showDialog(ancestorNoteId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function groupByDate(result) {
|
function groupByDate(rows) {
|
||||||
const groupedByDate = new Map();
|
const groupedByDate = new Map();
|
||||||
|
|
||||||
for (const row of result) {
|
for (const row of rows) {
|
||||||
const dateDay = row.date.substr(0, 10);
|
const dateDay = row.date.substr(0, 10);
|
||||||
|
|
||||||
if (!groupedByDate.has(dateDay)) {
|
if (!groupedByDate.has(dateDay)) {
|
||||||
|
@ -8,69 +8,55 @@ const noteCacheService = require('../../services/note_cache');
|
|||||||
async function getRecentChanges(req) {
|
async function getRecentChanges(req) {
|
||||||
const {ancestorNoteId} = req.params;
|
const {ancestorNoteId} = req.params;
|
||||||
|
|
||||||
const noteRows = await sql.getRows(
|
let recentChanges = [];
|
||||||
`
|
|
||||||
SELECT * FROM (
|
|
||||||
SELECT note_revisions.noteId,
|
|
||||||
note_revisions.noteRevisionId,
|
|
||||||
note_revisions.dateLastEdited AS date
|
|
||||||
FROM note_revisions
|
|
||||||
ORDER BY note_revisions.dateLastEdited DESC
|
|
||||||
)
|
|
||||||
UNION ALL SELECT * FROM (
|
|
||||||
SELECT
|
|
||||||
notes.noteId,
|
|
||||||
NULL AS noteRevisionId,
|
|
||||||
dateModified AS date
|
|
||||||
FROM notes
|
|
||||||
ORDER BY dateModified DESC
|
|
||||||
)
|
|
||||||
ORDER BY date DESC`);
|
|
||||||
|
|
||||||
const recentChanges = [];
|
const noteRevisions = await sql.getRows(`
|
||||||
|
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 utcDate,
|
||||||
|
note_revisions.dateCreated AS date
|
||||||
|
FROM
|
||||||
|
note_revisions
|
||||||
|
JOIN notes USING(noteId)`);
|
||||||
|
|
||||||
for (const noteRow of noteRows) {
|
for (const noteRevision of noteRevisions) {
|
||||||
if (!noteCacheService.isInAncestor(noteRow.noteId, ancestorNoteId)) {
|
if (noteCacheService.isInAncestor(noteRevision.noteId, ancestorNoteId)) {
|
||||||
continue;
|
recentChanges.push(noteRevision);
|
||||||
}
|
|
||||||
|
|
||||||
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.dateCreated 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.dateModified AS date
|
|
||||||
FROM
|
|
||||||
notes
|
|
||||||
WHERE noteId = ?`, [noteRow.noteId]));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recentChanges.length >= 200) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const notes = await sql.getRows(`
|
||||||
|
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.utcDateCreated AS utcDate,
|
||||||
|
notes.dateCreated AS date
|
||||||
|
FROM
|
||||||
|
notes`);
|
||||||
|
|
||||||
|
for (const note of notes) {
|
||||||
|
if (noteCacheService.isInAncestor(note.noteId, ancestorNoteId)) {
|
||||||
|
recentChanges.push(note);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
recentChanges.sort((a, b) => a.utcDate > b.utcDate ? -1 : 1);
|
||||||
|
|
||||||
|
recentChanges = recentChanges.slice(0, Math.min(500, recentChanges.length));
|
||||||
|
|
||||||
|
console.log(recentChanges);
|
||||||
|
|
||||||
for (const change of recentChanges) {
|
for (const change of recentChanges) {
|
||||||
if (change.current_isProtected) {
|
if (change.current_isProtected) {
|
||||||
if (protectedSessionService.isProtectedSessionAvailable()) {
|
if (protectedSessionService.isProtectedSessionAvailable()) {
|
||||||
@ -102,4 +88,4 @@ async function getRecentChanges(req) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getRecentChanges
|
getRecentChanges
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user