mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 21:19:01 +01: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,34 +8,9 @@ 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(`
 | 
				
			||||||
 | 
					 | 
				
			||||||
    for (const noteRow of noteRows) {
 | 
					 | 
				
			||||||
        if (!noteCacheService.isInAncestor(noteRow.noteId, ancestorNoteId)) {
 | 
					 | 
				
			||||||
            continue;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (noteRow.noteRevisionId) {
 | 
					 | 
				
			||||||
            recentChanges.push(await sql.getRow(`
 | 
					 | 
				
			||||||
        SELECT 
 | 
					        SELECT 
 | 
				
			||||||
            notes.noteId,
 | 
					            notes.noteId,
 | 
				
			||||||
            notes.isDeleted AS current_isDeleted,
 | 
					            notes.isDeleted AS current_isDeleted,
 | 
				
			||||||
@ -44,14 +19,19 @@ async function getRecentChanges(req) {
 | 
				
			|||||||
            notes.title AS current_title,
 | 
					            notes.title AS current_title,
 | 
				
			||||||
            notes.isProtected AS current_isProtected,
 | 
					            notes.isProtected AS current_isProtected,
 | 
				
			||||||
            note_revisions.title,
 | 
					            note_revisions.title,
 | 
				
			||||||
 | 
					            note_revisions.utcDateCreated AS utcDate,
 | 
				
			||||||
            note_revisions.dateCreated AS date
 | 
					            note_revisions.dateCreated AS date
 | 
				
			||||||
        FROM 
 | 
					        FROM 
 | 
				
			||||||
            note_revisions
 | 
					            note_revisions
 | 
				
			||||||
                    JOIN notes USING(noteId)
 | 
					            JOIN notes USING(noteId)`);
 | 
				
			||||||
                WHERE noteRevisionId = ?`, [noteRow.noteRevisionId]));
 | 
					
 | 
				
			||||||
 | 
					    for (const noteRevision of noteRevisions) {
 | 
				
			||||||
 | 
					        if (noteCacheService.isInAncestor(noteRevision.noteId, ancestorNoteId)) {
 | 
				
			||||||
 | 
					            recentChanges.push(noteRevision);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else {
 | 
					    }
 | 
				
			||||||
            recentChanges.push(await sql.getRow(`
 | 
					
 | 
				
			||||||
 | 
					    const notes = await sql.getRows(`
 | 
				
			||||||
        SELECT
 | 
					        SELECT
 | 
				
			||||||
            notes.noteId,
 | 
					            notes.noteId,
 | 
				
			||||||
            notes.isDeleted AS current_isDeleted,
 | 
					            notes.isDeleted AS current_isDeleted,
 | 
				
			||||||
@ -60,16 +40,22 @@ async function getRecentChanges(req) {
 | 
				
			|||||||
            notes.title AS current_title,
 | 
					            notes.title AS current_title,
 | 
				
			||||||
            notes.isProtected AS current_isProtected,
 | 
					            notes.isProtected AS current_isProtected,
 | 
				
			||||||
            notes.title,
 | 
					            notes.title,
 | 
				
			||||||
                    notes.dateModified AS date
 | 
					            notes.utcDateCreated AS utcDate,
 | 
				
			||||||
 | 
					            notes.dateCreated AS date
 | 
				
			||||||
        FROM
 | 
					        FROM
 | 
				
			||||||
                    notes
 | 
					            notes`);
 | 
				
			||||||
                WHERE noteId = ?`, [noteRow.noteId]));
 | 
					
 | 
				
			||||||
 | 
					    for (const note of notes) {
 | 
				
			||||||
 | 
					        if (noteCacheService.isInAncestor(note.noteId, ancestorNoteId)) {
 | 
				
			||||||
 | 
					            recentChanges.push(note);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (recentChanges.length >= 200) {
 | 
					    recentChanges.sort((a, b) => a.utcDate > b.utcDate ? -1 : 1);
 | 
				
			||||||
            break;
 | 
					
 | 
				
			||||||
        }
 | 
					    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) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user