Commit 51bc8f6b41ef93f18917bc07054c74c30412ad28
keep counts of total messages validated or queued
Dominic Tarr committed on 7/27/2017, 8:37:30 AMParent: 3ab042915e383de66498e28236438f61fa16b5fe
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -2,8 +2,10 @@ | ||
2 | 2 … | var ssbKeys = require('ssb-keys') |
3 | 3 … | |
4 | 4 … | exports.initial = function () { |
5 | 5 … | return { |
6 … | + validated: 0, | |
7 … | + queued: 0, | |
6 | 8 … | queue: [], |
7 | 9 … | feeds: {}, |
8 | 10 … | error: null |
9 | 11 … | } |
@@ -61,8 +63,9 @@ | ||
61 | 63 … | return state |
62 | 64 … | state.feeds[msg.author] = state.feeds[msg.author] || { |
63 | 65 … | id: null, sequence: null, timestamp: null, queue: [] |
64 | 66 … | } |
67 … | + state.queued += 1 | |
65 | 68 … | state.feeds[msg.author].queue.push(msg) |
66 | 69 … | return state |
67 | 70 … | } |
68 | 71 … | |
@@ -89,23 +92,27 @@ | ||
89 | 92 … | a.id = exports.id(msg) |
90 | 93 … | a.sequence = msg.sequence |
91 | 94 … | a.timestamp = msg.timestamp |
92 | 95 … | var q = state.feeds[msg.author].queue |
96 … | + state.validated += q.length | |
97 … | + state.queued -= q.length | |
93 | 98 … | while(q.length) |
94 | 99 … | state.queue.push(q.shift()) |
95 | 100 … | } |
96 | - else | |
101 … | + else { | |
97 | 102 … | state.feeds[msg.author] = {id: exports.id(msg), sequence: msg.sequence, timestamp: msg.timestamp, queue: []} |
98 | - | |
103 … | + } | |
99 | 104 … | state.queue.push(msg) |
105 … | + state.validated += 1 | |
100 | 106 … | return state |
101 | 107 … | } |
102 | 108 … | |
103 | 109 … | exports.validate = function (state, feed) { |
104 | 110 … | if(!state.feeds[feed] || !state.feeds[feed].queue.length) { |
105 | 111 … | return state |
106 | 112 … | } |
107 | 113 … | var msg = state.feeds[feed].queue.pop() |
114 … | + state.queued -= 1 | |
108 | 115 … | return exports.append(state, msg) |
109 | 116 … | } |
110 | 117 … | |
111 | 118 … | //pass in your own timestamp, so it's completely deterministic |
Built with git-ssb-web