mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	mini optimizations
This commit is contained in:
		
							parent
							
								
									7ef2e7769f
								
							
						
					
					
						commit
						3b690f5456
					
				@ -264,7 +264,7 @@ async function findExistencyIssues() {
 | 
			
		||||
        branches.parentNoteId,
 | 
			
		||||
        branches.noteId
 | 
			
		||||
      HAVING
 | 
			
		||||
        COUNT(*) > 1`,
 | 
			
		||||
        COUNT(1) > 1`,
 | 
			
		||||
    async ({noteId, parentNoteId}, autoFix) => {
 | 
			
		||||
        if (autoFix) {
 | 
			
		||||
            const branches = await repository.getEntities(
 | 
			
		||||
@ -636,11 +636,11 @@ async function showEntityStat(name, query) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function runDbDiagnostics() {
 | 
			
		||||
    await showEntityStat("Notes", `SELECT isDeleted, count(noteId) FROM notes GROUP BY isDeleted`);
 | 
			
		||||
    await showEntityStat("Note revisions", `SELECT isErased, count(noteRevisionId) FROM note_revisions GROUP BY isErased`);
 | 
			
		||||
    await showEntityStat("Branches", `SELECT isDeleted, count(branchId) FROM branches GROUP BY isDeleted`);
 | 
			
		||||
    await showEntityStat("Attributes", `SELECT isDeleted, count(attributeId) FROM attributes GROUP BY isDeleted`);
 | 
			
		||||
    await showEntityStat("API tokens", `SELECT isDeleted, count(apiTokenId) FROM api_tokens GROUP BY isDeleted`);
 | 
			
		||||
    await showEntityStat("Notes", `SELECT isDeleted, count(1) FROM notes GROUP BY isDeleted`);
 | 
			
		||||
    await showEntityStat("Note revisions", `SELECT isErased, count(1) FROM note_revisions GROUP BY isErased`);
 | 
			
		||||
    await showEntityStat("Branches", `SELECT isDeleted, count(1) FROM branches GROUP BY isDeleted`);
 | 
			
		||||
    await showEntityStat("Attributes", `SELECT isDeleted, count(1) FROM attributes GROUP BY isDeleted`);
 | 
			
		||||
    await showEntityStat("API tokens", `SELECT isDeleted, count(1) FROM api_tokens GROUP BY isDeleted`);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function runChecks() {
 | 
			
		||||
 | 
			
		||||
@ -228,9 +228,9 @@ async function checkContentHash(syncContext) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const notPushedSyncs = await sql.getValue("SELECT COUNT(*) FROM sync WHERE id > ?", [await getLastSyncedPush()]);
 | 
			
		||||
    const notPushedSyncs = await sql.getValue("SELECT EXISTS(SELECT 1 FROM sync WHERE id > ?)", [await getLastSyncedPush()]);
 | 
			
		||||
 | 
			
		||||
    if (notPushedSyncs > 0) {
 | 
			
		||||
    if (notPushedSyncs) {
 | 
			
		||||
        log.info(`There's ${notPushedSyncs} outstanding pushes, skipping content check.`);
 | 
			
		||||
 | 
			
		||||
        return;
 | 
			
		||||
@ -333,7 +333,7 @@ async function updatePushStats() {
 | 
			
		||||
    if (await syncOptions.isSyncSetup()) {
 | 
			
		||||
        const lastSyncedPush = await optionService.getOption('lastSyncedPush');
 | 
			
		||||
 | 
			
		||||
        stats.outstandingPushes = await sql.getValue("SELECT COUNT(*) FROM sync WHERE id > ?", [lastSyncedPush]);
 | 
			
		||||
        stats.outstandingPushes = await sql.getValue("SELECT COUNT(1) FROM sync WHERE id > ?", [lastSyncedPush]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -31,7 +31,7 @@ async function fillSyncRows(entityName, entityKey, condition = '') {
 | 
			
		||||
        let createdCount = 0;
 | 
			
		||||
 | 
			
		||||
        for (const entityId of entityIds) {
 | 
			
		||||
            const existingRows = await sql.getValue("SELECT COUNT(id) FROM sync WHERE entityName = ? AND entityId = ?", [entityName, entityId]);
 | 
			
		||||
            const existingRows = await sql.getValue("SELECT COUNT(1) FROM sync WHERE entityName = ? AND entityId = ?", [entityName, entityId]);
 | 
			
		||||
 | 
			
		||||
            // we don't want to replace existing entities (which would effectively cause full resync)
 | 
			
		||||
            if (existingRows === 0) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user