fix #5845 added run-gc on webex

This commit is contained in:
Sebastian 2022-04-29 13:16:29 -03:00
parent a1ad9727ee
commit 038dcbc9b7
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
4 changed files with 50 additions and 15 deletions

View File

@ -1303,9 +1303,9 @@ export const WALLET_BACKUP_STATE_KEY = "walletBackupState";
*/ */
export type ConfigRecord = export type ConfigRecord =
| { | {
key: typeof WALLET_BACKUP_STATE_KEY; key: typeof WALLET_BACKUP_STATE_KEY;
value: WalletBackupConfState; value: WalletBackupConfState;
} }
| { key: "currencyDefaultsApplied"; value: boolean }; | { key: "currencyDefaultsApplied"; value: boolean };
export interface WalletBackupConfState { export interface WalletBackupConfState {
@ -1491,17 +1491,17 @@ export enum BackupProviderStateTag {
export type BackupProviderState = export type BackupProviderState =
| { | {
tag: BackupProviderStateTag.Provisional; tag: BackupProviderStateTag.Provisional;
} }
| { | {
tag: BackupProviderStateTag.Ready; tag: BackupProviderStateTag.Ready;
nextBackupTimestamp: TalerProtocolTimestamp; nextBackupTimestamp: TalerProtocolTimestamp;
} }
| { | {
tag: BackupProviderStateTag.Retrying; tag: BackupProviderStateTag.Retrying;
retryInfo: RetryInfo; retryInfo: RetryInfo;
lastError?: TalerErrorDetail; lastError?: TalerErrorDetail;
}; };
export interface BackupProviderTerms { export interface BackupProviderTerms {
supportedProtocolVersion: string; supportedProtocolVersion: string;
@ -1895,7 +1895,6 @@ export function importDb(db: IDBDatabase, dump: DatabaseDump): Promise<any> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const tx = db.transaction(Array.from(db.objectStoreNames), "readwrite"); const tx = db.transaction(Array.from(db.objectStoreNames), "readwrite");
tx.addEventListener("complete", () => { tx.addEventListener("complete", () => {
tx.commit();
resolve(db); resolve(db);
}); });
for (let i = 0; i < db.objectStoreNames.length; i++) { for (let i = 0; i < db.objectStoreNames.length; i++) {
@ -1908,5 +1907,6 @@ export function importDb(db: IDBDatabase, dump: DatabaseDump): Promise<any> {
tx.objectStore(name).put(value); tx.objectStore(name).put(value);
}); });
} }
tx.commit();
}); });
} }

View File

@ -36,7 +36,8 @@ export function DeveloperPage(): VNode {
const [status, timedOut] = useDiagnostics(); const [status, timedOut] = useDiagnostics();
const listenAllEvents = Array.from<NotificationType>({ length: 1 }); const listenAllEvents = Array.from<NotificationType>({ length: 1 });
listenAllEvents.includes = () => true; // includes every event //FIXME: waiting for retry notification make a always increasing loop of notifications
listenAllEvents.includes = (e) => e !== "waiting-for-retry"; // includes every event
const response = useAsyncAsHook(async () => { const response = useAsyncAsHook(async () => {
const op = await wxApi.getPendingOperations(); const op = await wxApi.getPendingOperations();
@ -160,11 +161,22 @@ export function View({
onClick={() => onClick={() =>
confirmReset( confirmReset(
i18n.str`Do you want to IRREVOCABLY DESTROY everything inside your wallet and LOSE ALL YOUR COINS?`, i18n.str`Do you want to IRREVOCABLY DESTROY everything inside your wallet and LOSE ALL YOUR COINS?`,
wxApi.resetDb,
) )
} }
> >
<i18n.Translate>reset</i18n.Translate> <i18n.Translate>reset</i18n.Translate>
</button> </button>
<button
onClick={() =>
confirmReset(
i18n.str`TESTING: This may delete all your coin, proceed with caution`,
wxApi.runGarbageCollector,
)
}
>
<i18n.Translate>run gc</i18n.Translate>
</button>
<br /> <br />
<button onClick={() => fileRef?.current?.click()}> <button onClick={() => fileRef?.current?.click()}>
<i18n.Translate>import database</i18n.Translate> <i18n.Translate>import database</i18n.Translate>
@ -385,9 +397,10 @@ function toBase64(str: string): string {
export async function confirmReset( export async function confirmReset(
confirmTheResetMessage: string, confirmTheResetMessage: string,
cb: () => Promise<void>,
): Promise<void> { ): Promise<void> {
if (confirm(confirmTheResetMessage)) { if (confirm(confirmTheResetMessage)) {
await wxApi.resetDb(); await cb();
window.close(); window.close();
} }
} }

View File

@ -140,6 +140,14 @@ export function resetDb(): Promise<void> {
return callBackend("reset-db", {}); return callBackend("reset-db", {});
} }
/**
* Reset database
*/
export function runGarbageCollector(): Promise<void> {
return callBackend("run-gc", {});
}
export function getFeeForDeposit( export function getFeeForDeposit(
depositPaytoUri: string, depositPaytoUri: string,
amount: AmountString, amount: AmountString,

View File

@ -33,6 +33,8 @@ import {
import { import {
DbAccess, DbAccess,
deleteTalerDatabase, deleteTalerDatabase,
exportDb,
importDb,
makeErrorDetail, makeErrorDetail,
OpenedPromise, OpenedPromise,
openPromise, openPromise,
@ -129,6 +131,18 @@ async function dispatch(
r = wrapResponse(await reinitWallet()); r = wrapResponse(await reinitWallet());
break; break;
} }
case "run-gc": {
logger.info("gc")
const dump = await exportDb(currentDatabase!.idbHandle());
await deleteTalerDatabase(indexedDB as any);
logger.info("cleaned")
await reinitWallet();
logger.info("init")
await importDb(currentDatabase!.idbHandle(), dump)
logger.info("imported")
r = wrapResponse({ result: true });
break;
}
case "containsHeaderListener": { case "containsHeaderListener": {
const res = await platform.containsTalerHeaderListener(); const res = await platform.containsTalerHeaderListener();
r = wrapResponse({ newValue: res }); r = wrapResponse({ newValue: res });