Porting db health to single worker mode.

This commit is contained in:
vdv committed 2023-02-12 10:46:26 +01:00
1 parent 0d86b789c1
commit 89689c5ed6
2 files changed
+218 -36

No files matched your search

+29 -36
View File
@@ -1,17 +1,9 @@
import _ from 'lodash';
import PouchDB from 'pouchdb';
import indexeddb from 'pouchdb-adapter-indexeddb';
import { watchDbLegacy } from '../db-admin/health-legacy';
import { openDatabases } from '../db-admin/open';
import uri from '../lib/ids';
import { toHex } from '../lib/to-hex';
import {
getAccountById,
getAccounts,
initialAccount,
putAccount,
} from './account';
import changeHandler from './change-handler';
import { getSettings, putSettings } from './settings';
declare global {
var localDb: any;
@@ -51,33 +43,33 @@ export const initDb = async () => {
});
}
if (globalThis.sync) {
globalThis.sync
.on('change', function (info) {
// handle change
console.log({ caller: 'Sync / change', info });
})
.on('paused', function (err) {
// replication paused (e.g. replication up to date, user went offline)
console.log({ caller: 'Sync / paused', err });
})
.on('active', function () {
// replicate resumed (e.g. new changes replicating, user went back online)
console.log({ caller: 'Sync / active' });
})
.on('denied', function (err) {
// a document failed to replicate (e.g. due to permissions)
console.error({ caller: 'Sync / denied', err });
})
.on('complete', function (info) {
// handle complete
console.log({ caller: 'Sync / complete', info });
})
.on('error', function (err) {
// handle error
console.error({ caller: 'Sync / error', err });
});
}
// if (globalThis.sync) {
// globalThis.sync
// .on('change', function (info) {
// // handle change
// console.log({ caller: 'Sync / change', info });
// })
// .on('paused', function (err) {
// // replication paused (e.g. replication up to date, user went offline)
// console.log({ caller: 'Sync / paused', err });
// })
// .on('active', function () {
// // replicate resumed (e.g. new changes replicating, user went back online)
// console.log({ caller: 'Sync / active' });
// })
// .on('denied', function (err) {
// // a document failed to replicate (e.g. due to permissions)
// console.error({ caller: 'Sync / denied', err });
// })
// .on('complete', function (info) {
// // handle complete
// console.log({ caller: 'Sync / complete', info });
// })
// .on('error', function (err) {
// // handle error
// console.error({ caller: 'Sync / error', err });
// });
// }
// console.log({ caller: 'initDb / before db.changes' });
@@ -106,5 +98,6 @@ export const initDb = async () => {
// changes.cancel();
globalThis.dbReady = true;
watchDbLegacy();
}
};