mirror of https://codeberg.org/pzp/pzp-db.git
add API logStats(cb)
This commit is contained in:
parent
a6749cafa1
commit
5a405be367
13
lib/index.js
13
lib/index.js
|
@ -400,7 +400,10 @@ function initDB(peer, config) {
|
||||||
const data = msg.data
|
const data = msg.data
|
||||||
if (data.action === 'add') {
|
if (data.action === 'add') {
|
||||||
// Does this msg.pubkey have the "add" power?
|
// Does this msg.pubkey have the "add" power?
|
||||||
const keypair = { curve: 'ed25519', public: msg.pubkey }
|
const keypair = {
|
||||||
|
curve: /** @type {const} */ ('ed25519'),
|
||||||
|
public: msg.pubkey,
|
||||||
|
}
|
||||||
const powers = getAccountPowers(accountTangle, keypair)
|
const powers = getAccountPowers(accountTangle, keypair)
|
||||||
if (!powers.has('add')) {
|
if (!powers.has('add')) {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
|
@ -939,6 +942,13 @@ function initDB(peer, config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {CB<{ totalBytes: number; deletedBytes: number }>} cb
|
||||||
|
*/
|
||||||
|
function logStats(cb) {
|
||||||
|
log.stats(cb)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// public
|
// public
|
||||||
installEncryptionFormat,
|
installEncryptionFormat,
|
||||||
|
@ -964,6 +974,7 @@ function initDB(peer, config) {
|
||||||
getTangle,
|
getTangle,
|
||||||
msgs,
|
msgs,
|
||||||
records,
|
records,
|
||||||
|
logStats,
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
findEncryptionFormatFor,
|
findEncryptionFormatFor,
|
||||||
|
|
|
@ -21,7 +21,7 @@ test('add()', async (t) => {
|
||||||
|
|
||||||
await peer.db.loaded()
|
await peer.db.loaded()
|
||||||
|
|
||||||
const accountMsg0 = MsgV3.createAccount(keypair, 'person')
|
const accountMsg0 = MsgV3.createAccount(keypair, 'person', 'aliceNonce')
|
||||||
const id = MsgV3.getMsgID(accountMsg0)
|
const id = MsgV3.getMsgID(accountMsg0)
|
||||||
|
|
||||||
await p(peer.db.add)(accountMsg0, id)
|
await p(peer.db.add)(accountMsg0, id)
|
||||||
|
@ -48,5 +48,9 @@ test('add()', async (t) => {
|
||||||
const rec = await p(peer.db.add)(inputMsg, rootID)
|
const rec = await p(peer.db.add)(inputMsg, rootID)
|
||||||
assert.equal(rec.msg.data.text, 'This is the first post!')
|
assert.equal(rec.msg.data.text, 'This is the first post!')
|
||||||
|
|
||||||
|
await p(peer.db._getLog().onDrain)()
|
||||||
|
const stats = await p(peer.db.logStats)()
|
||||||
|
assert.deepEqual(stats, { totalBytes: 974, deletedBytes: 0 })
|
||||||
|
|
||||||
await p(peer.close)(true)
|
await p(peer.close)(true)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue