perf: load database parallel to decrypting
This commit is contained in:
parent
e84e3c3f70
commit
ea9b8b509a
4 changed files with 60 additions and 56 deletions
|
@ -1,7 +1,4 @@
|
|||
import {
|
||||
BackupDecryptor,
|
||||
type DecryptionResult,
|
||||
} from "@duskflower/signal-decrypt-backup-wasm";
|
||||
import { BackupDecryptor } from "@duskflower/signal-decrypt-backup-wasm";
|
||||
|
||||
const CHUNK_SIZE = 1024 * 1024 * 40; // 40MB chunks
|
||||
|
||||
|
@ -9,7 +6,8 @@ export async function decryptBackup(
|
|||
file: File,
|
||||
passphrase: string,
|
||||
progressCallback: (progress: number) => void,
|
||||
): Promise<DecryptionResult> {
|
||||
statementsCallback?: (statements: string[]) => void | Promise<void>,
|
||||
): Promise<string[]> {
|
||||
const fileSize = file.size;
|
||||
const decryptor = new BackupDecryptor();
|
||||
decryptor.set_progress_callback(fileSize, progressCallback);
|
||||
|
@ -34,6 +32,8 @@ export async function decryptBackup(
|
|||
}
|
||||
}
|
||||
|
||||
await statementsCallback?.(decryptor.get_new_decrypted_statements());
|
||||
|
||||
offset += CHUNK_SIZE;
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ import { Flex } from "~/components/ui/flex";
|
|||
|
||||
import { Progress, ProgressLabel, ProgressValueLabel } from "~/components/ui/progress";
|
||||
import { loadDb } from "~/db";
|
||||
import { decryptBackup } from "~/lib/decryptor";
|
||||
import { decryptBackup } from "~/lib/backup-decryptor";
|
||||
import { createDropzone, createFileUploader } from "@solid-primitives/upload";
|
||||
import { Button } from "~/components/ui/button";
|
||||
import { TextField, TextFieldInput, TextFieldLabel } from "~/components/ui/text-field";
|
||||
|
@ -53,19 +53,23 @@ export const Home: Component<RouteSectionProps> = () => {
|
|||
|
||||
// setDbHash(hash);
|
||||
|
||||
decryptBackup(currentBackupFile, currentPassphrase, setDecryptionProgress)
|
||||
.then(async (decrypted) => {
|
||||
console.time();
|
||||
decryptBackup(currentBackupFile, currentPassphrase, setDecryptionProgress, async (statements) => {
|
||||
await loadDb(statements);
|
||||
})
|
||||
.then(() => {
|
||||
umami.track("Decrypt backup");
|
||||
setDecryptionProgress(undefined);
|
||||
// setIsLoadingDatabase(true);
|
||||
setLoadingProgress(0);
|
||||
// setLoadingProgress(0);
|
||||
|
||||
await loadDb(decrypted.database_statements, setLoadingProgress);
|
||||
// await loadDb(decrypted.database_statements, setLoadingProgress);
|
||||
umami.track("Load database");
|
||||
|
||||
// setIsLoadingDatabase(false);
|
||||
setLoadingProgress(undefined);
|
||||
// setLoadingProgress(undefined);
|
||||
|
||||
console.timeEnd();
|
||||
navigate("/overview");
|
||||
})
|
||||
.catch((error) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue