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
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -81,7 +81,7 @@ function initConductor(peer, config) {
|
|||
* @param {Array<Rule>} rules
|
||||
*/
|
||||
function countGhostableFeeds(rules) {
|
||||
let count = 2 // 'follow' and 'block' Sets
|
||||
let count = 2 // 'follows' and 'blocks' Sets
|
||||
for (const rule of rules) {
|
||||
const [, goalDSL] = parseRule(rule)
|
||||
if (goalDSL === 'dict') count++
|
||||
|
@ -115,7 +115,7 @@ function initConductor(peer, config) {
|
|||
const [myRules, theirRules] = rules
|
||||
|
||||
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) {
|
||||
estimateMsgCount += getRealisticCount(rule)
|
||||
}
|
||||
|
@ -151,13 +151,13 @@ function initConductor(peer, config) {
|
|||
function setupAccountGoals(accountID, rules) {
|
||||
peer.goals.set(accountID, 'all')
|
||||
|
||||
const followDomain = peer.set.getDomain('follow')
|
||||
const followFeedID = peer.db.feed.getID(accountID, followDomain)
|
||||
peer.goals.set(followFeedID, 'set')
|
||||
const followsDomain = peer.set.getDomain('follows')
|
||||
const followsFeedID = peer.db.feed.getID(accountID, followsDomain)
|
||||
peer.goals.set(followsFeedID, 'set')
|
||||
|
||||
const blockDomain = peer.set.getDomain('block')
|
||||
const blockFeedID = peer.db.feed.getID(accountID, blockDomain)
|
||||
peer.goals.set(blockFeedID, 'set')
|
||||
const blocksDomain = peer.set.getDomain('blocks')
|
||||
const blocksFeedID = peer.db.feed.getID(accountID, blocksDomain)
|
||||
peer.goals.set(blocksFeedID, 'set')
|
||||
|
||||
for (const rule of rules) {
|
||||
const [domain, goalDSL] = parseRule(rule)
|
||||
|
@ -166,7 +166,7 @@ function initConductor(peer, config) {
|
|||
}
|
||||
|
||||
// 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) {
|
||||
peer.goals.set(accountID, 'none')
|
||||
|
||||
const followDomain = peer.set.getDomain('follow')
|
||||
const followFeedID = peer.db.feed.getID(accountID, followDomain)
|
||||
peer.goals.set(followFeedID, 'none')
|
||||
const followsDomain = peer.set.getDomain('follows')
|
||||
const followsFeedID = peer.db.feed.getID(accountID, followsDomain)
|
||||
peer.goals.set(followsFeedID, 'none')
|
||||
|
||||
const blockDomain = peer.set.getDomain('block')
|
||||
const blockFeedID = peer.db.feed.getID(accountID, blockDomain)
|
||||
peer.goals.set(blockFeedID, 'none')
|
||||
const blocksDomain = peer.set.getDomain('blocks')
|
||||
const blocksFeedID = peer.db.feed.getID(accountID, blocksDomain)
|
||||
peer.goals.set(blocksFeedID, 'none')
|
||||
|
||||
for (const rule of rules) {
|
||||
const [domain] = parseRule(rule)
|
||||
|
@ -191,7 +191,7 @@ function initConductor(peer, config) {
|
|||
}
|
||||
|
||||
// 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}`)
|
||||
}
|
||||
if (maxBytes > MAX_RECOMMENDED_MAXBYTES) {
|
||||
debug(
|
||||
'WARNING. maxBytes is too big, we recommend at most %s bytes',
|
||||
MAX_RECOMMENDED_MAXBYTES
|
||||
)
|
||||
// prettier-ignore
|
||||
debug('WARNING. maxBytes is too big, we recommend at most %s bytes', MAX_RECOMMENDED_MAXBYTES)
|
||||
}
|
||||
|
||||
const followedAccounts = peer.set.values('follow')
|
||||
const numFollowed = followedAccounts.length
|
||||
const [myRules, theirRules] = validateRules(rules, numFollowed, maxBytes)
|
||||
const follows = peer.set.values('follows')
|
||||
const numFollows = follows.length
|
||||
const [myRules, theirRules] = validateRules(rules, numFollows, maxBytes)
|
||||
|
||||
// Set up goals for my account and each account I follow
|
||||
setupAccountGoals(myID, myRules)
|
||||
for (const theirID of followedAccounts) {
|
||||
for (const theirID of follows) {
|
||||
setupAccountGoals(theirID, theirRules)
|
||||
}
|
||||
// @ts-ignore
|
||||
peer.set.watch(({ event, subdomain, value }) => {
|
||||
const theirID = value
|
||||
if (subdomain === 'follow' && event === 'add') {
|
||||
if (subdomain === 'follows' && event === 'add') {
|
||||
setupAccountGoals(theirID, theirRules)
|
||||
}
|
||||
if (subdomain === 'follow' && event === 'del') {
|
||||
if (subdomain === 'follows' && event === 'del') {
|
||||
teardownAccountGoals(theirID, theirRules)
|
||||
}
|
||||
if (subdomain === 'block' && event === 'add') {
|
||||
|
@ -240,7 +238,7 @@ function initConductor(peer, config) {
|
|||
// Figure out ghost span for each account
|
||||
const totalGhostableFeeds =
|
||||
countGhostableFeeds(myRules) +
|
||||
numFollowed * countGhostableFeeds(theirRules)
|
||||
numFollows * countGhostableFeeds(theirRules)
|
||||
const TOTAL_GHOSTS = ESTIMATE_TOTAL_GHOST_BYTES / MSG_ID_BYTES
|
||||
const ghostSpan = Math.round(TOTAL_GHOSTS / totalGhostableFeeds)
|
||||
peer.set.setGhostSpan(ghostSpan)
|
||||
|
|
|
@ -63,7 +63,7 @@ test('Replicate selected feeds of followed accounts', async (t) => {
|
|||
}
|
||||
|
||||
// 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)
|
||||
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
|
||||
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)
|
||||
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
|
||||
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)
|
||||
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'
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
assert.deepEqual(
|
||||
|
@ -320,7 +320,7 @@ test('GC recently-blocked accounts', async (t) => {
|
|||
}
|
||||
|
||||
// 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)
|
||||
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)
|
||||
|
||||
// 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)
|
||||
bob.conductor.start(bobID, [['post@all'], ['post@all']], 4_000)
|
||||
|
|
Loading…
Reference in New Issue