git ssb

1+

Dominic / secure-scuttlebutt



Tree: 8e8434f441e3e179672053fbde29570a4fcf6981

Files: 8e8434f441e3e179672053fbde29570a4fcf6981 / db.js

1459 bytesRaw
1//var ViewHashTable = require('flumeview-hashtable')
2var Box = require('./box')
3
4module.exports = function (dir, keys, opts) {
5 var boxes = Box(keys, opts)
6
7 var db = require('./minimal')(dir, keys, opts, boxes.map)
8 db.addUnboxer = boxes.addUnboxer
9 db.unbox = boxes.unbox
10 db.addMap = boxes.addMap
11
12 db.use('keys', require('./indexes/keys')())
13 .use('clock', require('./indexes/clock')())
14
15 db.progress = {}
16 var prog = db.progress.indexes = {
17 start: 0,
18 current: 0,
19 target: 0
20 }
21 var ts = Date.now()
22
23 db.since(function () {
24 prog.target = db.since.value
25 if (Date.now() > ts + 100) { update() }
26 })
27
28 //call to update status and progress.
29 function update () {
30 ts = Date.now()
31 // iterate over the current views, so we capture plugins
32 // as well as the built ins.
33 var current = 0
34 var n = 0
35 for (var k in db) {
36 if (db[k] && typeof db[k].since === 'function') {
37 n++
38 var c = db[k].since.value
39 current += (Number.isInteger(c) ? c : -1)
40 }
41 }
42 prog.current = ~~(current / n)
43 // if the progress bar is complete, move the starting point
44 // up to the current position!
45 if (prog.start <= 0) {
46 prog.start = prog.current
47 } else if (prog.current === prog.target) {
48 prog.start = prog.target
49 }
50 }
51
52 // unref is only available when running inside node
53 var timer = setInterval(update, 200)
54 timer.unref && timer.unref()
55
56 return db
57}
58
59

Built with git-ssb-web