mirror of
https://github.com/zadam/trilium.git
synced 2025-11-18 03:00:41 +01:00
progress of tar import through WS
This commit is contained in:
@@ -430,7 +430,7 @@ async function runChecks() {
|
||||
|
||||
await runAllChecks();
|
||||
|
||||
elapsedTimeMs = new Date().getTime() - startTime.getTime();
|
||||
elapsedTimeMs = Date.now() - startTime.getTime();
|
||||
});
|
||||
|
||||
if (fixedIssues) {
|
||||
|
||||
@@ -42,7 +42,7 @@ async function getHashes() {
|
||||
links: await getHash(Link)
|
||||
};
|
||||
|
||||
const elapseTimeMs = new Date().getTime() - startTime.getTime();
|
||||
const elapseTimeMs = Date.now() - startTime.getTime();
|
||||
|
||||
log.info(`Content hash computation took ${elapseTimeMs}ms`);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ const utils = require('../../services/utils');
|
||||
const log = require('../../services/log');
|
||||
const repository = require('../../services/repository');
|
||||
const noteService = require('../../services/notes');
|
||||
const messagingService = require('../../services/messaging');
|
||||
const Branch = require('../../entities/branch');
|
||||
const tar = require('tar-stream');
|
||||
const stream = require('stream');
|
||||
@@ -13,7 +14,12 @@ const path = require('path');
|
||||
const commonmark = require('commonmark');
|
||||
const mimeTypes = require('mime-types');
|
||||
|
||||
let importNoteCount;
|
||||
let lastSentCountTs = Date.now();
|
||||
|
||||
async function importTar(fileBuffer, importRootNote) {
|
||||
importNoteCount = 0;
|
||||
|
||||
// maps from original noteId (in tar file) to newly generated noteId
|
||||
const noteIdMap = {};
|
||||
const attributes = [];
|
||||
@@ -287,7 +293,7 @@ async function importTar(fileBuffer, importRootNote) {
|
||||
}
|
||||
}
|
||||
|
||||
/** @return path without leading or trailing slash and backslashes converted to forward ones*/
|
||||
/** @return {string} path without leading or trailing slash and backslashes converted to forward ones*/
|
||||
function normalizeFilePath(filePath) {
|
||||
filePath = filePath.replace(/\\/g, "/");
|
||||
|
||||
@@ -314,7 +320,7 @@ async function importTar(fileBuffer, importRootNote) {
|
||||
// call next when you are done with this entry
|
||||
|
||||
stream.on('end', async function() {
|
||||
let filePath = normalizeFilePath(header.name);
|
||||
const filePath = normalizeFilePath(header.name);
|
||||
|
||||
const content = Buffer.concat(chunks);
|
||||
|
||||
@@ -331,6 +337,14 @@ async function importTar(fileBuffer, importRootNote) {
|
||||
log.info("Ignoring tar import entry with type " + header.type);
|
||||
}
|
||||
|
||||
importNoteCount++;
|
||||
|
||||
if (Date.now() - lastSentCountTs >= 1000) {
|
||||
lastSentCountTs = Date.now();
|
||||
|
||||
messagingService.sendMessageToAllClients({ type: 'importNoteCount', count: importNoteCount });
|
||||
}
|
||||
|
||||
next(); // ready for next entry
|
||||
});
|
||||
|
||||
|
||||
@@ -397,7 +397,7 @@ async function deleteNote(branch) {
|
||||
}
|
||||
|
||||
async function cleanupDeletedNotes() {
|
||||
const cutoffDate = new Date(new Date().getTime() - 48 * 3600 * 1000);
|
||||
const cutoffDate = new Date(Date.now() - 48 * 3600 * 1000);
|
||||
|
||||
// it's better to not use repository for this because it will complain about saving protected notes
|
||||
// out of protected session
|
||||
|
||||
@@ -132,7 +132,7 @@ async function pullSync(syncContext) {
|
||||
}
|
||||
|
||||
log.info("Pulled " + rows.length + " changes from " + changesUri + " in "
|
||||
+ (new Date().getTime() - startDate.getTime()) + "ms");
|
||||
+ (Date.now() - startDate.getTime()) + "ms");
|
||||
|
||||
for (const {sync, entity} of rows) {
|
||||
if (!sourceIdService.isLocalSourceId(sync.sourceId)) {
|
||||
@@ -194,7 +194,7 @@ async function pushSync(syncContext) {
|
||||
entities: syncRecords
|
||||
});
|
||||
|
||||
log.info(`Pushing ${syncRecords.length} syncs in ` + (new Date().getTime() - startDate.getTime()) + "ms");
|
||||
log.info(`Pushing ${syncRecords.length} syncs in ` + (Date.now() - startDate.getTime()) + "ms");
|
||||
|
||||
lastSyncedPush = syncRecords[syncRecords.length - 1].sync.id;
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ async function stopWatch(what, func) {
|
||||
|
||||
const ret = await func();
|
||||
|
||||
const tookMs = new Date().getTime() - start.getTime();
|
||||
const tookMs = Date.now() - start.getTime();
|
||||
|
||||
console.log(`${what} took ${tookMs}ms`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user