git ssb

0+

Dominic / ssb-validate



Tree: 3ab042915e383de66498e28236438f61fa16b5fe

Files: 3ab042915e383de66498e28236438f61fa16b5fe / dump.js

1315 bytesRaw
1var validate = require('./')
2var pull = require('pull-stream')
3var state = {
4 queue: [],
5 feeds: {},
6 error: null
7}
8require('ssb-client')(function (err, sbot) {
9 var c = 0, _c = 0, e = 0, d = 0, q = 0, ts = Date.now(), start = Date.now()
10
11 function log () {
12 if(Date.now() > ts + 1000) {
13 var s = (ts - start)/1000
14 console.log(c, c - _c, d, e, q, c / s, s)
15 _c = c
16 d = 0
17 ts = Date.now()
18 }
19 }
20
21 var author = null
22
23 pull(
24 sbot.createLogStream(),
25 pull.drain(function (data) {
26 if(author && data.value.author != author && state.feeds[author].queue.length > 20) {
27 q -= state.feeds[author].queue.length
28 state = validate.validate(state, author)
29 state = validate.queue(state, data.value)
30 q++
31 }
32 else {
33 q++
34 state = validate.queue(state, data.value)
35 }
36
37 author = data.value.author
38
39 if(state.error) {
40 e++
41 console.log(state.error)
42 state.error = null
43 }
44 else if(state.queue.length)
45 d += JSON.stringify(state.queue.shift(), null, 2).length //can gc it
46 log()
47 c++
48 }, function () {
49 for(var k in state.feeds) {
50 if(state.feeds[k].queue.length)
51 validate.validate(state, k)
52 log()
53 }
54 })
55 )
56
57})
58
59
60
61
62
63
64
65
66
67
68

Built with git-ssb-web