update secret-stack to 8.1

This commit is contained in:
Andre Staltz 2024-01-08 11:38:24 +02:00
parent e0af1c5669
commit 2809d7bb50
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
4 changed files with 6 additions and 29 deletions

View File

@ -23,30 +23,10 @@ const makeDebug = require('debug')
*/
/**
* @param {{ db: PPPPPDB | null }} peer
* @returns {asserts peer is { db: PPPPPDB }}
*/
function assertDBPlugin(peer) {
if (!peer.db) throw new Error('"gc" plugin requires "db" plugin')
}
/**
* @param {{ goals: PPPPPGoal | null }} peer
* @returns {asserts peer is { goals: PPPPPGoal }}
*/
function assertGoalsPlugin(peer) {
if (!peer.goals) throw new Error('"gc" plugin requires "goals" plugin')
}
/**
* @param {{ db: PPPPPDB | null, goals: PPPPPGoal | null }} peer
* @param {{ db: PPPPPDB, goals: PPPPPGoal }} peer
* @param {Config} config
*/
function initGC(peer, config) {
// Assertions
assertDBPlugin(peer)
assertGoalsPlugin(peer)
// State
const debug = makeDebug('ppppp:gc')
let stopMonitoringLogSize = /** @type {CallableFunction | null} */ (null)
@ -58,8 +38,6 @@ function initGC(peer, config) {
* @param {CB<void>} cb
*/
function cleanup(cb) {
assertDBPlugin(peer)
assertGoalsPlugin(peer)
debug('Cleanup started')
const startTime = Date.now()
@ -104,7 +82,6 @@ function initGC(peer, config) {
* @param {CB<void>} cb
*/
function compact(cb) {
assertDBPlugin(peer)
debug('Compaction started')
const startTime = Date.now()
peer.db.log.compact((err) => {
@ -165,13 +142,10 @@ function initGC(peer, config) {
* @param {number} maxLogBytes
*/
function monitorLogSize(maxLogBytes) {
assertDBPlugin(peer)
/** Number of records that match roughly 1% of the max log size */
const CHECKPOINT = Math.floor((maxLogBytes * 0.01) / 500) // assuming 1 record = 500 bytes
function checkLogSize() {
assertDBPlugin(peer)
peer.db.log.stats((err, stats) => {
if (err) return
const percentUsed = (stats.totalBytes / maxLogBytes) * 100
@ -248,4 +222,5 @@ function initGC(peer, config) {
}
exports.name = 'gc'
exports.needs = ['db', 'goals']
exports.init = initGC

View File

@ -36,11 +36,12 @@
"ppppp-dict": "github:staltz/ppppp-dict",
"ppppp-goals": "github:staltz/ppppp-goals",
"ppppp-keypair": "github:staltz/ppppp-keypair",
"ppppp-set": "github:staltz/ppppp-set",
"prettier": "^2.6.2",
"pretty-quick": "^3.1.3",
"rimraf": "^4.4.0",
"secret-handshake-ext": "0.0.11",
"secret-stack": "~8.0.0",
"secret-stack": "~8.1.0",
"ssb-box": "^1.0.1",
"typescript": "^5.1.3"
},

View File

@ -29,6 +29,7 @@ function createPeer(config) {
.use(require('secret-handshake-ext/secret-stack'))
.use(require('ppppp-db'))
.use(require('ppppp-dict'))
.use(require('ppppp-set'))
.use(require('ppppp-goals'))
.use(require('ssb-box'))
.use(require('../lib'))

View File

@ -11,6 +11,6 @@
"module": "node16",
"skipLibCheck": true,
"strict": true,
"target": "es2021"
"target": "es2022"
}
}