mirror of https://codeberg.org/pzp/pzp-gc.git
refactor (cosmetic)
This commit is contained in:
parent
c7dc78b859
commit
a85403dd34
18
lib/index.js
18
lib/index.js
|
@ -26,7 +26,7 @@ const makeDebug = require('debug')
|
|||
* @param {{ db: PPPPPDB | null }} peer
|
||||
* @returns {asserts peer is { db: PPPPPDB }}
|
||||
*/
|
||||
function assertDBExists(peer) {
|
||||
function assertDBPlugin(peer) {
|
||||
if (!peer.db) throw new Error('gc plugin requires ppppp-db plugin')
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ function assertDBExists(peer) {
|
|||
* @param {{ goals: PPPPPGoal | null }} peer
|
||||
* @returns {asserts peer is { goals: PPPPPGoal }}
|
||||
*/
|
||||
function assertGoalsExists(peer) {
|
||||
function assertGoalsPlugin(peer) {
|
||||
if (!peer.goals) throw new Error('gc plugin requires ppppp-goals plugin')
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,8 @@ function assertValidConfig(config) {
|
|||
*/
|
||||
function initGC(peer, config) {
|
||||
// Assertions
|
||||
assertDBExists(peer)
|
||||
assertGoalsExists(peer)
|
||||
assertDBPlugin(peer)
|
||||
assertGoalsPlugin(peer)
|
||||
assertValidConfig(config)
|
||||
|
||||
// Constants
|
||||
|
@ -74,8 +74,8 @@ function initGC(peer, config) {
|
|||
* @param {CB<void>} cb
|
||||
*/
|
||||
function cleanup(cb) {
|
||||
assertDBExists(peer)
|
||||
assertGoalsExists(peer)
|
||||
assertDBPlugin(peer)
|
||||
assertGoalsPlugin(peer)
|
||||
debug('cleanup-per-purpose started')
|
||||
|
||||
const done = multicb({ pluck: 1 })
|
||||
|
@ -120,7 +120,7 @@ function initGC(peer, config) {
|
|||
* @param {CB<void>} cb
|
||||
*/
|
||||
function compact(waitPeriod, cb) {
|
||||
assertDBExists(peer)
|
||||
assertDBPlugin(peer)
|
||||
const log = peer.db._getLog() // TODO: use public API?
|
||||
debug('compaction started')
|
||||
/** @param {Error=} err */
|
||||
|
@ -140,9 +140,9 @@ function initGC(peer, config) {
|
|||
* Monitor the log size and schedule compaction and/or cleanup.
|
||||
*/
|
||||
function monitorLogSize() {
|
||||
assertDBExists(peer)
|
||||
assertDBPlugin(peer)
|
||||
function checkLogSize() {
|
||||
assertDBExists(peer)
|
||||
assertDBPlugin(peer)
|
||||
assertValidConfig(config)
|
||||
peer.db.logStats((err, stats) => {
|
||||
if (err) return
|
||||
|
|
Loading…
Reference in New Issue