add API logStats(cb)

This commit is contained in:
Andre Staltz 2023-09-13 14:27:53 +03:00
parent a6749cafa1
commit 5a405be367
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 17 additions and 2 deletions

View File

@ -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,

View File

@ -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)
}) })