mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-05 21:56:42 +00:00
Merge pull request #1088 from orbitdb/fix/instance-caching
Fix db instance caching
This commit is contained in:
commit
ebbaf60bd3
@ -131,6 +131,10 @@ const OrbitDB = async ({ ipfs, id, identities, directory } = {}) => {
|
||||
address = OrbitDBAddress(m.hash)
|
||||
name = manifest.name
|
||||
meta = manifest.meta
|
||||
// Check if we already have the database open and return if it is
|
||||
if (databases[address]) {
|
||||
return databases[address]
|
||||
}
|
||||
}
|
||||
|
||||
Database = Database || getDatabaseType(type)()
|
||||
|
@ -527,4 +527,39 @@ describe('Open databases', function () {
|
||||
deepStrictEqual(all.map(e => e.value), expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('opening same database', () => {
|
||||
let db
|
||||
|
||||
before(async () => {
|
||||
orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1' })
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (db) {
|
||||
await db.close()
|
||||
}
|
||||
if (orbitdb1) {
|
||||
await orbitdb1.stop()
|
||||
}
|
||||
await rmrf('./orbitdb')
|
||||
})
|
||||
|
||||
it('returns the database instance when opened with a name multiple times', async () => {
|
||||
let err
|
||||
let db1, db2
|
||||
|
||||
try {
|
||||
db1 = await orbitdb1.open('helloworld1')
|
||||
db2 = await orbitdb1.open('helloworld1')
|
||||
} catch (e) {
|
||||
err = e
|
||||
}
|
||||
|
||||
strictEqual(err, undefined)
|
||||
strictEqual(db1.name, 'helloworld1')
|
||||
strictEqual(db2.name, 'helloworld1')
|
||||
strictEqual(db1.address, db2.address)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user