mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
Update examples and benchmarks
This commit is contained in:
parent
8e4f22e0f3
commit
39408d0e2a
@ -1,6 +1,6 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const IPFS = require('ipfs-api')
|
const IPFS = require('ipfs-http-client')
|
||||||
const OrbitDB = require('../src/OrbitDB')
|
const OrbitDB = require('../src/OrbitDB')
|
||||||
|
|
||||||
// Metrics
|
// Metrics
|
||||||
@ -26,7 +26,7 @@ const ipfs = IPFS('127.0.0.1')
|
|||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
try {
|
try {
|
||||||
const orbit = new OrbitDB(ipfs, './orbitdb/benchmarks')
|
const orbit = await OrbitDB.createInstance(ipfs, { directory: './orbitdb/benchmarks' })
|
||||||
const db = await orbit.eventlog('orbit-db.benchmark', {
|
const db = await orbit.eventlog('orbit-db.benchmark', {
|
||||||
replicate: false,
|
replicate: false,
|
||||||
})
|
})
|
||||||
|
@ -44,7 +44,7 @@ ipfs.on('error', (err) => console.error(err))
|
|||||||
ipfs.on('ready', async () => {
|
ipfs.on('ready', async () => {
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
try {
|
try {
|
||||||
const orbit = new OrbitDB(ipfs, './orbitdb/benchmarks')
|
const orbit = await OrbitDB.createInstance(ipfs,{ directory: './orbitdb/benchmarks' })
|
||||||
const db = await orbit.eventlog('orbit-db.benchmark', {
|
const db = await orbit.eventlog('orbit-db.benchmark', {
|
||||||
replicate: false,
|
replicate: false,
|
||||||
})
|
})
|
||||||
|
@ -87,7 +87,7 @@ pMapSeries([conf1,], d => startIpfs('js-ipfs', d))
|
|||||||
.then(async ([ipfs1]) => {
|
.then(async ([ipfs1]) => {
|
||||||
try {
|
try {
|
||||||
// Create the databases
|
// Create the databases
|
||||||
const orbit1 = new OrbitDB(ipfs1.api, './orbitdb/benchmarks/replication/client1')
|
const orbit1 = await OrbitDB.createInstance(ipfs1.api, { directory: './orbitdb/benchmarks/replication/client1' })
|
||||||
const db1 = await orbit1.eventlog(database, { overwrite: true })
|
const db1 = await orbit1.eventlog(database, { overwrite: true })
|
||||||
console.log(db1.address.toString())
|
console.log(db1.address.toString())
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ pMapSeries([conf2], d => startIpfs('js-ipfs', d))
|
|||||||
.then(async ([ipfs2]) => {
|
.then(async ([ipfs2]) => {
|
||||||
try {
|
try {
|
||||||
// Create the databases
|
// Create the databases
|
||||||
const orbit2 = new OrbitDB(ipfs2.api, './orbitdb/benchmarks/replication/client2')
|
const orbit2 = await OrbitDB.createInstance(ipfs2.api, { directory: './orbitdb/benchmarks/replication/client2' })
|
||||||
const address = process.argv[2]
|
const address = process.argv[2]
|
||||||
const db2 = await orbit2.eventlog(address)
|
const db2 = await orbit2.eventlog(address)
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
ipfs.on('ready', async () => {
|
ipfs.on('ready', async () => {
|
||||||
const outputElm = document.getElementById('output')
|
const outputElm = document.getElementById('output')
|
||||||
try {
|
try {
|
||||||
const orbit = new OrbitDB(ipfs, './orbitdb/benchmarks/browser')
|
const orbit = await OrbitDB.createInstance(ipfs, { directory: './orbitdb/benchmarks/browser' })
|
||||||
const db = await orbit.eventlog('orbit-db.benchmark.add', {
|
const db = await orbit.eventlog('orbit-db.benchmark.add', {
|
||||||
replicate: false,
|
replicate: false,
|
||||||
})
|
})
|
||||||
|
@ -98,7 +98,7 @@
|
|||||||
let ipfs1 = await startIpfs(conf1)
|
let ipfs1 = await startIpfs(conf1)
|
||||||
try {
|
try {
|
||||||
// Create the databases
|
// Create the databases
|
||||||
const orbit1 = new OrbitDB(ipfs1, './orbitdb/benchmarks/replication/client1')
|
const orbit1 = await OrbitDB.createInstance(ipfs1, { directory: './orbitdb/benchmarks/replication/client1' })
|
||||||
const db1 = await orbit1.eventlog(database, { overwrite: true, sync: false })
|
const db1 = await orbit1.eventlog(database, { overwrite: true, sync: false })
|
||||||
|
|
||||||
console.log("Database address is:", db1.address.toString())
|
console.log("Database address is:", db1.address.toString())
|
||||||
|
@ -109,8 +109,8 @@
|
|||||||
let ipfs2 = await startIpfs(conf2)
|
let ipfs2 = await startIpfs(conf2)
|
||||||
try {
|
try {
|
||||||
// Create the databases
|
// Create the databases
|
||||||
const address = '/orbitdb/QmcPCAwwV1rw7cLQU7VcCaUXEuLYSCH8uUf6NPDLYbL6JT/benchmark-replication'
|
const address = '/orbitdb/zdpuArNFJaH4Fk5dHH4rYSCtmbyaJLNHUyeFX4WszFxEqwJTE/benchmark-replication'
|
||||||
const orbit2 = new OrbitDB(ipfs2, './orbitdb/benchmarks/replication/client3')
|
const orbit2 = await OrbitDB.createInstance(ipfs2, { directory: './orbitdb/benchmarks/replication/client3' })
|
||||||
const db2 = await orbit2.eventlog(address)
|
const db2 = await orbit2.eventlog(address)
|
||||||
|
|
||||||
db2.events.on('peer', peer => console.log("PEER2!", peer))
|
db2.events.on('peer', peer => console.log("PEER2!", peer))
|
||||||
|
@ -51,8 +51,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="writerText"></div>
|
<div id="writerText"></div>
|
||||||
|
|
||||||
<script type="text/javascript" src="lib/orbitdb.min.js" charset="utf-8"></script>
|
<script type="text/javascript" src="../../dist/orbitdb.js" charset="utf-8"></script>
|
||||||
<script type="text/javascript" src="lib/ipfs.js" charset="utf-8"></script>
|
<script type="text/javascript" src="../../node_modules/ipfs/dist/index.js" charset="utf-8"></script>
|
||||||
<script type="text/javascript" src="example.js" charset="utf-8"></script>
|
<script type="text/javascript" src="example.js" charset="utf-8"></script>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
// Start the example
|
// Start the example
|
||||||
|
@ -46,8 +46,11 @@ const main = (IPFS, ORBITDB) => {
|
|||||||
|
|
||||||
// Create IPFS instance
|
// Create IPFS instance
|
||||||
const ipfs = new Ipfs({
|
const ipfs = new Ipfs({
|
||||||
repo: '/orbitdb/examples/browser/new/ipfs/0.27.3',
|
repo: '/orbitdb/examples/browser/new/ipfs/0.33.1',
|
||||||
start: true,
|
start: true,
|
||||||
|
preload: {
|
||||||
|
enabled: false
|
||||||
|
},
|
||||||
EXPERIMENTAL: {
|
EXPERIMENTAL: {
|
||||||
pubsub: true,
|
pubsub: true,
|
||||||
},
|
},
|
||||||
@ -65,11 +68,11 @@ const main = (IPFS, ORBITDB) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ipfs.on('error', (e) => handleError(e))
|
ipfs.on('error', (e) => handleError(e))
|
||||||
ipfs.on('ready', () => {
|
ipfs.on('ready', async () => {
|
||||||
openButton.disabled = false
|
openButton.disabled = false
|
||||||
createButton.disabled = false
|
createButton.disabled = false
|
||||||
statusElm.innerHTML = "IPFS Started"
|
statusElm.innerHTML = "IPFS Started"
|
||||||
orbitdb = new OrbitDB(ipfs)
|
orbitdb = await OrbitDB.createInstance(ipfs)
|
||||||
})
|
})
|
||||||
|
|
||||||
const load = async (db, statusText) => {
|
const load = async (db, statusText) => {
|
||||||
@ -89,8 +92,8 @@ const main = (IPFS, ORBITDB) => {
|
|||||||
let maxTotal = 0, loaded = 0
|
let maxTotal = 0, loaded = 0
|
||||||
db.events.on('load.progress', (address, hash, entry, progress, total) => {
|
db.events.on('load.progress', (address, hash, entry, progress, total) => {
|
||||||
loaded ++
|
loaded ++
|
||||||
maxTotal = Math.max.apply(null, [progress, maxTotal, progress, 0])
|
maxTotal = Math.max.apply(null, [maxTotal, progress, 0])
|
||||||
total = Math.max.apply(null, [progress, maxTotal, total, 0])
|
total = Math.max.apply(null, [progress, maxTotal, total, entry.clock.time, 0])
|
||||||
statusElm.innerHTML = `Loading database... ${maxTotal} / ${total}`
|
statusElm.innerHTML = `Loading database... ${maxTotal} / ${total}`
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -158,7 +161,9 @@ const main = (IPFS, ORBITDB) => {
|
|||||||
type: type,
|
type: type,
|
||||||
// If "Public" flag is set, allow anyone to write to the database,
|
// If "Public" flag is set, allow anyone to write to the database,
|
||||||
// otherwise only the creator of the database can write
|
// otherwise only the creator of the database can write
|
||||||
write: publicAccess ? ['*'] : [],
|
accessController: {
|
||||||
|
write: publicAccess ? ['*'] : [identity.publicKey],
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await load(db, 'Creating database...')
|
await load(db, 'Creating database...')
|
||||||
@ -255,7 +260,7 @@ const main = (IPFS, ORBITDB) => {
|
|||||||
outputElm.innerHTML = `
|
outputElm.innerHTML = `
|
||||||
<div><b>Peer ID:</b> ${orbitdb.id}</div>
|
<div><b>Peer ID:</b> ${orbitdb.id}</div>
|
||||||
<div><b>Peers (database/network):</b> ${databasePeers.length} / ${networkPeers.length}</div>
|
<div><b>Peers (database/network):</b> ${databasePeers.length} / ${networkPeers.length}</div>
|
||||||
<div><b>Oplog Size:</b> ${db._replicationStatus.progress} / ${db._replicationStatus.max}</div>
|
<div><b>Oplog Size:</b> ${Math.max(db._replicationStatus.progress, db._oplog.length)} / ${db._replicationStatus.max}</div>
|
||||||
<h2>Results</h2>
|
<h2>Results</h2>
|
||||||
<div id="results">
|
<div id="results">
|
||||||
<div>
|
<div>
|
||||||
|
@ -21,8 +21,11 @@ ipfs.on('ready', async () => {
|
|||||||
let db
|
let db
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const orbitdb = new OrbitDB(ipfs, './orbitdb/examples/eventlog')
|
const orbitdb = await OrbitDB.createInstance(ipfs, {
|
||||||
|
directory: './orbitdb/examples/eventlog'
|
||||||
|
})
|
||||||
db = await orbitdb.eventlog('example', { overwrite: true })
|
db = await orbitdb.eventlog('example', { overwrite: true })
|
||||||
|
await db.load()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
@ -40,7 +43,7 @@ ipfs.on('ready', async () => {
|
|||||||
output += `--------------------\n`
|
output += `--------------------\n`
|
||||||
output += `ID | Visitor\n`
|
output += `ID | Visitor\n`
|
||||||
output += `--------------------\n`
|
output += `--------------------\n`
|
||||||
output += latest.reverse().map((e) => e.payload.value.userId + ' | ' + e.payload.value.avatar + ')').join('\n') + `\n`
|
output += latest.reverse().map((e) => e.payload.value.userId + ' | ' + e.payload.value.avatar).join('\n') + `\n`
|
||||||
console.log(output)
|
console.log(output)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
@ -36,7 +36,9 @@ ipfs.on('error', (err) => console.error(err))
|
|||||||
ipfs.on('ready', async () => {
|
ipfs.on('ready', async () => {
|
||||||
let db
|
let db
|
||||||
try {
|
try {
|
||||||
const orbitdb = new OrbitDB(ipfs, './orbitdb/examples/eventlog')
|
const orbitdb = await OrbitDB.createInstance(ipfs, {
|
||||||
|
directory: './orbitdb/examples/keyvalue'
|
||||||
|
})
|
||||||
db = await orbitdb.kvstore('example', { overwrite: true })
|
db = await orbitdb.kvstore('example', { overwrite: true })
|
||||||
await db.load()
|
await db.load()
|
||||||
// Query immediately after loading
|
// Query immediately after loading
|
||||||
|
Loading…
x
Reference in New Issue
Block a user