'use strict' ; import Collection from '../../src/core/Collection' ; const IPFS = require ( 'ipfs' ) ; const OrbitDB = require ( 'orbit-db' ) ; const Crypto = require ( 'crypto' ) ; const rimraf = require ( 'rimraf' ) ; const { config } = require ( 'orbit-db-test-utils' ) ; rimraf . sync ( "./orbitdb" ) ; let totalQueries = 0 ; let seconds = 0 ; let queriesPerSecond = 0 ; let lastTenSeconds = 0 ; const numberOfEntries = 5000 ; const queryLoop = async ( db ) => { await db . updateOne ( { nombre : "kim" } , { $set : { age : 35 } } ) ; totalQueries ++ ; lastTenSeconds ++ ; queriesPerSecond ++ ; setImmediate ( ( ) => queryLoop ( db ) ) ; } ; console . log ( "Starting IPFS daemon..." ) ; const ipfsConfig = Object . assign ( { } , config . defaultIpfsConfig , { repo : config . defaultIpfsConfig . repo + '-entry' + new Date ( ) . getTime ( ) } ) ; IPFS . create ( ipfsConfig ) . then ( async ( ipfs ) => { const run = async ( ) => { try { OrbitDB . addDatabaseType ( "aviondb.collection" , Collection ) ; const orbit = await OrbitDB . createInstance ( ipfs , { directory : './orbitdb/benchmarks' } ) ; const db = await orbit . create ( 'orbit-db.benchmark' , "aviondb.collection" , { replicate : false , overwrite : true } ) ; console . log ( `Creating ${ numberOfEntries } documents for updating. Stand by! ` ) ; for ( let x = 0 ; x < numberOfEntries ; x ++ ) { await db . insertOne ( { id : Crypto . randomBytes ( 6 ) . toString ( "base64" ) , nombre : "kim" } ) ; } setInterval ( ( ) => { seconds ++ ; if ( seconds % 10 === 0 ) { console . log ( `--> Average of ${ lastTenSeconds / 10 } q/s in the last 10 seconds` ) ; if ( lastTenSeconds === 0 ) throw new Error ( "Problems!" ) ; lastTenSeconds = 0 ; } console . log ( `${ queriesPerSecond } queries per second, ${ totalQueries } queries in ${ seconds } seconds (Oplog: ${ db . _oplog . length })` ) ; queriesPerSecond = 0 ; } , 1000 ) ; queryLoop ( db ) ; } catch ( e ) { console . log ( e ) ; process . exit ( 1 ) ; } } ; run ( ) ; } ) . catch ( error => { console . log ( error ) ; } ) ;