setGhostSpan

This commit is contained in:
Andre Staltz 2023-12-21 12:19:26 +02:00
parent c4faaf27ce
commit 39b3364137
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 13 additions and 2 deletions

View File

@ -90,7 +90,7 @@ function assert(check, message) {
function initSet(peer, config) { function initSet(peer, config) {
assertDBPlugin(peer) assertDBPlugin(peer)
const ghostSpan = config.set?.ghostSpan ?? 32 let ghostSpan = config.set?.ghostSpan ?? 32
if (ghostSpan < 1) throw new Error('config.set.ghostSpan must be >= 0') if (ghostSpan < 1) throw new Error('config.set.ghostSpan must be >= 0')
//#region state //#region state
@ -531,6 +531,15 @@ function initSet(peer, config) {
return ghostSpan return ghostSpan
} }
/**
* @param {number} span
* @returns {void}
*/
function setGhostSpan(span) {
if (span < 1) throw new Error('ghostSpan must be >= 0')
ghostSpan = span
}
/** /**
* @param {any} subdomain * @param {any} subdomain
*/ */
@ -583,6 +592,7 @@ function initSet(peer, config) {
getFeedID, getFeedID,
isGhostable, isGhostable,
getGhostSpan, getGhostSpan,
setGhostSpan,
minGhostDepth, minGhostDepth,
minRequiredDepth, minRequiredDepth,
squeeze, squeeze,

View File

@ -19,7 +19,7 @@ test('setup', async (t) => {
peer = createPeer({ peer = createPeer({
keypair: aliceKeypair, keypair: aliceKeypair,
db: { path: DIR }, db: { path: DIR },
set: { ghostSpan: 4 }, set: { ghostSpan: 40 },
}) })
await peer.db.loaded() await peer.db.loaded()
@ -30,6 +30,7 @@ test('setup', async (t) => {
}) })
await p(peer.set.load)(aliceID) await p(peer.set.load)(aliceID)
peer.set.setGhostSpan(4)
assert.equal(peer.set.getGhostSpan(), 4, 'getGhostSpan') assert.equal(peer.set.getGhostSpan(), 4, 'getGhostSpan')
}) })