Skip to content

Commit

Permalink
Make sure hops() auto drains the contacts index
Browse files Browse the repository at this point in the history
  • Loading branch information
arj03 committed Feb 4, 2021
1 parent e5397f9 commit 274e0a0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
14 changes: 9 additions & 5 deletions index.js
Expand Up @@ -100,12 +100,16 @@ exports.init = function (sbot, config) {

// legacy, debugging
hops (opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = {}
}

layered.onReady(function () {
if (typeof opts === 'function') {
cb = opts
opts = {}
}
cb(null, layered.getHops(opts))
if (sbot.db)
sbot.db.onDrain('contacts', () => cb(null, layered.getHops(opts)))
else
cb(null, layered.getHops(opts))
})
},
help: () => help,
Expand Down
42 changes: 20 additions & 22 deletions test/db2.js
Expand Up @@ -84,31 +84,29 @@ tape('db2 friends test', function (t) {
}),
addMsg(sbot.db, carol, u.follow(alice.id))
])(function (err, results) {
sbot.db.onDrain('contacts', () => {
sbot.friends.hops(function (err, hops) {
if (err) throw err
t.deepEqual(live, hops)

sbot.close(() => {
sbot = Server({
keys: alice,
db2: true,
path: dir
})
live = liveFriends(sbot)
sbot.friends.hops(function (err, hops) {
if (err) throw err
t.deepEqual(live, hops)

sbot.close(() => {
sbot = Server({
keys: alice,
db2: true,
path: dir
})
live = liveFriends(sbot)

addMsg(sbot.db, bob, {
type: 'contact',
contact: carol.id,
following: true
})((err) => {
if (err) throw err
addMsg(sbot.db, bob, {
type: 'contact',
contact: carol.id,
following: true
})((err) => {
if (err) throw err

sbot.db.onDrain('contacts', () => {
t.deepEqual(live, hops)
sbot.db.onDrain('contacts', () => {
t.deepEqual(live, hops)

sbot.close(t.end)
})
sbot.close(t.end)
})
})
})
Expand Down

0 comments on commit 274e0a0

Please sign in to comment.