change subdomain "follow" to "follows"
This commit is contained in:
parent
c7fc2554df
commit
d4fe7aabd9
56
lib/index.js
56
lib/index.js
|
@ -56,9 +56,9 @@ function initConductor(peer, config) {
|
||||||
const ESTIMATE_TOTAL_GHOST_BYTES = 1024 * 1024 // 1 MB
|
const ESTIMATE_TOTAL_GHOST_BYTES = 1024 * 1024 // 1 MB
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many msgs does the average 'follow' Set feed contain
|
* How many msgs does the average 'follows' Set feed contain
|
||||||
*/
|
*/
|
||||||
const ESTIMATE_FOLLOW_FEED_SIZE = 300
|
const ESTIMATE_FOLLOWS_FEED_SIZE = 300
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many msgs does the average 'block' Set feed contain
|
* How many msgs does the average 'block' Set feed contain
|
||||||
|
@ -81,7 +81,7 @@ function initConductor(peer, config) {
|
||||||
* @param {Array<Rule>} rules
|
* @param {Array<Rule>} rules
|
||||||
*/
|
*/
|
||||||
function countGhostableFeeds(rules) {
|
function countGhostableFeeds(rules) {
|
||||||
let count = 2 // 'follow' and 'block' Sets
|
let count = 2 // 'follows' and 'blocks' Sets
|
||||||
for (const rule of rules) {
|
for (const rule of rules) {
|
||||||
const [, goalDSL] = parseRule(rule)
|
const [, goalDSL] = parseRule(rule)
|
||||||
if (goalDSL === 'dict') count++
|
if (goalDSL === 'dict') count++
|
||||||
|
@ -115,7 +115,7 @@ function initConductor(peer, config) {
|
||||||
const [myRules, theirRules] = rules
|
const [myRules, theirRules] = rules
|
||||||
|
|
||||||
let estimateMsgCount =
|
let estimateMsgCount =
|
||||||
(1 + numFollowed) * ESTIMATE_FOLLOW_FEED_SIZE + ESTIMATE_BLOCK_FEED_SIZE
|
(1 + numFollowed) * ESTIMATE_FOLLOWS_FEED_SIZE + ESTIMATE_BLOCK_FEED_SIZE
|
||||||
for (const rule of myRules) {
|
for (const rule of myRules) {
|
||||||
estimateMsgCount += getRealisticCount(rule)
|
estimateMsgCount += getRealisticCount(rule)
|
||||||
}
|
}
|
||||||
|
@ -151,13 +151,13 @@ function initConductor(peer, config) {
|
||||||
function setupAccountGoals(accountID, rules) {
|
function setupAccountGoals(accountID, rules) {
|
||||||
peer.goals.set(accountID, 'all')
|
peer.goals.set(accountID, 'all')
|
||||||
|
|
||||||
const followDomain = peer.set.getDomain('follow')
|
const followsDomain = peer.set.getDomain('follows')
|
||||||
const followFeedID = peer.db.feed.getID(accountID, followDomain)
|
const followsFeedID = peer.db.feed.getID(accountID, followsDomain)
|
||||||
peer.goals.set(followFeedID, 'set')
|
peer.goals.set(followsFeedID, 'set')
|
||||||
|
|
||||||
const blockDomain = peer.set.getDomain('block')
|
const blocksDomain = peer.set.getDomain('blocks')
|
||||||
const blockFeedID = peer.db.feed.getID(accountID, blockDomain)
|
const blocksFeedID = peer.db.feed.getID(accountID, blocksDomain)
|
||||||
peer.goals.set(blockFeedID, 'set')
|
peer.goals.set(blocksFeedID, 'set')
|
||||||
|
|
||||||
for (const rule of rules) {
|
for (const rule of rules) {
|
||||||
const [domain, goalDSL] = parseRule(rule)
|
const [domain, goalDSL] = parseRule(rule)
|
||||||
|
@ -166,7 +166,7 @@ function initConductor(peer, config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
debug('Setup goals for %s@all, %s@set, %s@set, %s', accountID, followDomain, blockDomain, rules.join(', '))
|
debug('Setup goals for %s@all, %s@set, %s@set, %s', accountID, followsDomain, blocksDomain, rules.join(', '))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -176,13 +176,13 @@ function initConductor(peer, config) {
|
||||||
function teardownAccountGoals(accountID, rules) {
|
function teardownAccountGoals(accountID, rules) {
|
||||||
peer.goals.set(accountID, 'none')
|
peer.goals.set(accountID, 'none')
|
||||||
|
|
||||||
const followDomain = peer.set.getDomain('follow')
|
const followsDomain = peer.set.getDomain('follows')
|
||||||
const followFeedID = peer.db.feed.getID(accountID, followDomain)
|
const followsFeedID = peer.db.feed.getID(accountID, followsDomain)
|
||||||
peer.goals.set(followFeedID, 'none')
|
peer.goals.set(followsFeedID, 'none')
|
||||||
|
|
||||||
const blockDomain = peer.set.getDomain('block')
|
const blocksDomain = peer.set.getDomain('blocks')
|
||||||
const blockFeedID = peer.db.feed.getID(accountID, blockDomain)
|
const blocksFeedID = peer.db.feed.getID(accountID, blocksDomain)
|
||||||
peer.goals.set(blockFeedID, 'none')
|
peer.goals.set(blocksFeedID, 'none')
|
||||||
|
|
||||||
for (const rule of rules) {
|
for (const rule of rules) {
|
||||||
const [domain] = parseRule(rule)
|
const [domain] = parseRule(rule)
|
||||||
|
@ -191,7 +191,7 @@ function initConductor(peer, config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
debug('Teardown goals for %s@all, %s@set, %s@set, %s', accountID, followDomain, blockDomain, rules.join(', '))
|
debug('Teardown goals for %s@all, %s@set, %s@set, %s', accountID, followsDomain, blocksDomain, rules.join(', '))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -208,28 +208,26 @@ function initConductor(peer, config) {
|
||||||
throw new Error(`ppppp-conductor maxBytes must be at least ${MIN_MAXBYTES} bytes, got ${maxBytes}`)
|
throw new Error(`ppppp-conductor maxBytes must be at least ${MIN_MAXBYTES} bytes, got ${maxBytes}`)
|
||||||
}
|
}
|
||||||
if (maxBytes > MAX_RECOMMENDED_MAXBYTES) {
|
if (maxBytes > MAX_RECOMMENDED_MAXBYTES) {
|
||||||
debug(
|
// prettier-ignore
|
||||||
'WARNING. maxBytes is too big, we recommend at most %s bytes',
|
debug('WARNING. maxBytes is too big, we recommend at most %s bytes', MAX_RECOMMENDED_MAXBYTES)
|
||||||
MAX_RECOMMENDED_MAXBYTES
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const followedAccounts = peer.set.values('follow')
|
const follows = peer.set.values('follows')
|
||||||
const numFollowed = followedAccounts.length
|
const numFollows = follows.length
|
||||||
const [myRules, theirRules] = validateRules(rules, numFollowed, maxBytes)
|
const [myRules, theirRules] = validateRules(rules, numFollows, maxBytes)
|
||||||
|
|
||||||
// Set up goals for my account and each account I follow
|
// Set up goals for my account and each account I follow
|
||||||
setupAccountGoals(myID, myRules)
|
setupAccountGoals(myID, myRules)
|
||||||
for (const theirID of followedAccounts) {
|
for (const theirID of follows) {
|
||||||
setupAccountGoals(theirID, theirRules)
|
setupAccountGoals(theirID, theirRules)
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
peer.set.watch(({ event, subdomain, value }) => {
|
peer.set.watch(({ event, subdomain, value }) => {
|
||||||
const theirID = value
|
const theirID = value
|
||||||
if (subdomain === 'follow' && event === 'add') {
|
if (subdomain === 'follows' && event === 'add') {
|
||||||
setupAccountGoals(theirID, theirRules)
|
setupAccountGoals(theirID, theirRules)
|
||||||
}
|
}
|
||||||
if (subdomain === 'follow' && event === 'del') {
|
if (subdomain === 'follows' && event === 'del') {
|
||||||
teardownAccountGoals(theirID, theirRules)
|
teardownAccountGoals(theirID, theirRules)
|
||||||
}
|
}
|
||||||
if (subdomain === 'block' && event === 'add') {
|
if (subdomain === 'block' && event === 'add') {
|
||||||
|
@ -240,7 +238,7 @@ function initConductor(peer, config) {
|
||||||
// Figure out ghost span for each account
|
// Figure out ghost span for each account
|
||||||
const totalGhostableFeeds =
|
const totalGhostableFeeds =
|
||||||
countGhostableFeeds(myRules) +
|
countGhostableFeeds(myRules) +
|
||||||
numFollowed * countGhostableFeeds(theirRules)
|
numFollows * countGhostableFeeds(theirRules)
|
||||||
const TOTAL_GHOSTS = ESTIMATE_TOTAL_GHOST_BYTES / MSG_ID_BYTES
|
const TOTAL_GHOSTS = ESTIMATE_TOTAL_GHOST_BYTES / MSG_ID_BYTES
|
||||||
const ghostSpan = Math.round(TOTAL_GHOSTS / totalGhostableFeeds)
|
const ghostSpan = Math.round(TOTAL_GHOSTS / totalGhostableFeeds)
|
||||||
peer.set.setGhostSpan(ghostSpan)
|
peer.set.setGhostSpan(ghostSpan)
|
||||||
|
|
|
@ -63,7 +63,7 @@ test('Replicate selected feeds of followed accounts', async (t) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alice follows Bob, but not Carol
|
// Alice follows Bob, but not Carol
|
||||||
assert(await p(alice.set.add)('follow', bobID), 'alice follows bob')
|
assert(await p(alice.set.add)('follows', bobID), 'alice follows bob')
|
||||||
|
|
||||||
alice.conductor.start(aliceID, [['post@all'], ['post@all']], 64_000_000)
|
alice.conductor.start(aliceID, [['post@all'], ['post@all']], 64_000_000)
|
||||||
bob.conductor.start(bobID, [['post@all'], ['post@all']], 64_000_000)
|
bob.conductor.start(bobID, [['post@all'], ['post@all']], 64_000_000)
|
||||||
|
@ -141,7 +141,7 @@ test('GC selected feeds of followed accounts', async (t) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alice follows Bob, but not Carol
|
// Alice follows Bob, but not Carol
|
||||||
assert(await p(alice.set.add)('follow', bobID), 'alice follows bob')
|
assert(await p(alice.set.add)('follows', bobID), 'alice follows bob')
|
||||||
|
|
||||||
alice.conductor.start(aliceID, [['post@all'], ['post@all']], 64_000_000)
|
alice.conductor.start(aliceID, [['post@all'], ['post@all']], 64_000_000)
|
||||||
bob.conductor.start(bobID, [['post@all'], ['post@all']], 64_000_000)
|
bob.conductor.start(bobID, [['post@all'], ['post@all']], 64_000_000)
|
||||||
|
@ -233,7 +233,7 @@ test('GC recently-unfollowed accounts', async (t) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alice follows Bob, but not Carol
|
// Alice follows Bob, but not Carol
|
||||||
assert(await p(alice.set.add)('follow', bobID), 'alice follows bob')
|
assert(await p(alice.set.add)('follows', bobID), 'alice follows bob')
|
||||||
|
|
||||||
alice.conductor.start(aliceID, [['post@all'], ['post@all']], 4_000)
|
alice.conductor.start(aliceID, [['post@all'], ['post@all']], 4_000)
|
||||||
bob.conductor.start(bobID, [['post@all'], ['post@all']], 4_000)
|
bob.conductor.start(bobID, [['post@all'], ['post@all']], 4_000)
|
||||||
|
@ -248,7 +248,7 @@ test('GC recently-unfollowed accounts', async (t) => {
|
||||||
'alice has alice and bob posts'
|
'alice has alice and bob posts'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert(await p(alice.set.del)('follow', bobID), 'alice unfollows bob')
|
assert(await p(alice.set.del)('follows', bobID), 'alice unfollows bob')
|
||||||
await p(setTimeout)(1000)
|
await p(setTimeout)(1000)
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
|
@ -320,7 +320,7 @@ test('GC recently-blocked accounts', async (t) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alice follows Bob, but not Carol
|
// Alice follows Bob, but not Carol
|
||||||
assert(await p(alice.set.add)('follow', bobID), 'alice follows bob')
|
assert(await p(alice.set.add)('follows', bobID), 'alice follows bob')
|
||||||
|
|
||||||
alice.conductor.start(aliceID, [['post@all'], ['post@all']], 4_000)
|
alice.conductor.start(aliceID, [['post@all'], ['post@all']], 4_000)
|
||||||
bob.conductor.start(bobID, [['post@all'], ['post@all']], 4_000)
|
bob.conductor.start(bobID, [['post@all'], ['post@all']], 4_000)
|
||||||
|
@ -383,7 +383,7 @@ test('Set and Dict ghost spans', async (t) => {
|
||||||
await p(carol.set.load)(bobID)
|
await p(carol.set.load)(bobID)
|
||||||
|
|
||||||
// Alice follows Bob, but not Carol
|
// Alice follows Bob, but not Carol
|
||||||
assert(await p(alice.set.add)('follow', bobID), 'alice follows bob')
|
assert(await p(alice.set.add)('follows', bobID), 'alice follows bob')
|
||||||
|
|
||||||
alice.conductor.start(aliceID, [['post@all'], ['post@all']], 4_000)
|
alice.conductor.start(aliceID, [['post@all'], ['post@all']], 4_000)
|
||||||
bob.conductor.start(bobID, [['post@all'], ['post@all']], 4_000)
|
bob.conductor.start(bobID, [['post@all'], ['post@all']], 4_000)
|
||||||
|
|
Loading…
Reference in New Issue