1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-10 22:11:50 +02:00

Chore: Resolves #12814: Add additional logging to DecryptionWorker and EncryptionService (#12824)

This commit is contained in:
Henry Heino
2025-08-01 09:39:37 -07:00
committed by GitHub
parent 0089c62493
commit 763e3f7479
3 changed files with 21 additions and 5 deletions

View File

@@ -115,9 +115,17 @@ export default class PerformanceLogger {
}
}
private startCounter_ = 0;
public taskStart(name: string) {
// To prevent incorrect output in the browser's visual performance graph, the IDs
// passed to "performance.mark" need to be unique (or at least no other task with
// the same ID should be running at the same time). Add a counter to the task name
// to handle the case where two tasks with the otherwise same name run at the same
// time:
const uniqueTaskId = `${name}-${(this.startCounter_++)}`;
if (typeof performance.mark === 'function') {
performance.mark(`${name}-start`);
performance.mark(`${uniqueTaskId}-start`);
}
const startTime = performance.now();
@@ -128,8 +136,8 @@ export default class PerformanceLogger {
const now = performance.now();
this.lastLogTime_ = now;
if (hasPerformanceMarkApi) {
performance.mark(`${name}-end`);
performance.measure(name, `${name}-start`, `${name}-end`);
performance.mark(`${uniqueTaskId}-end`);
performance.measure(name, `${uniqueTaskId}-start`, `${uniqueTaskId}-end`);
}
const duration = now - startTime;

View File

@@ -193,6 +193,7 @@ export default class DecryptionWorker {
this.dispatch({ type: 'ENCRYPTION_HAS_DISABLED_ITEMS', value: false });
this.dispatchReport({ state: 'started' });
const decryptItemsTask = perfLogger.taskStart('DecryptionWorker/decryptItems');
try {
const notLoadedMasterKeyDispatches = [];
@@ -292,6 +293,8 @@ export default class DecryptionWorker {
this.state_ = 'idle';
this.dispatchReport({ state: 'idle' });
throw error;
} finally {
decryptItemsTask.onEnd();
}
// 2019-05-12: Temporary to set the file size of the resources

View File

@@ -6,9 +6,11 @@ import MasterKey from '../../models/MasterKey';
import BaseItem from '../../models/BaseItem';
import JoplinError from '../../JoplinError';
import { getActiveMasterKeyId, setActiveMasterKeyId } from '../synchronizer/syncInfoUtils';
import PerformanceLogger from '../../PerformanceLogger';
const { padLeft } = require('../../string-utils.js');
const logger = Logger.create('EncryptionService');
const perfLogger = PerformanceLogger.create();
const emptyUint8Array = new Uint8Array(0);
@@ -177,7 +179,7 @@ export default class EncryptionService {
public async loadMasterKey(model: MasterKeyEntity, getPassword: string|GetPasswordCallback, makeActive = false) {
if (!model.id) throw new Error('Master key does not have an ID - save it first');
const loadKey = async () => {
const loadKey = () => perfLogger.track('EncryptionService/loadKey', async () => {
logger.info(`Loading master key: ${model.id}. Make active:`, makeActive);
const password = typeof getPassword === 'string' ? getPassword : (await getPassword());
@@ -197,7 +199,7 @@ export default class EncryptionService {
}
this.encryptedMasterKeys_.delete(model.id);
};
});
if (!makeActive) {
this.encryptedMasterKeys_.set(model.id, {
@@ -337,10 +339,13 @@ export default class EncryptionService {
}
public async checkMasterKeyPassword(model: MasterKeyEntity, password: string) {
const task = perfLogger.taskStart('EncryptionService/checkMasterKeyPassword');
try {
await this.decryptMasterKeyContent(model, password);
} catch (error) {
return false;
} finally {
task.onEnd();
}
return true;