git ssb

1+

Dominic / secure-scuttlebutt



Commit fe399b8ac15da7a6c0cae09a3d9cfa47ac11818e

move feedDB into its own index

Dominic Tarr committed on 8/30/2016, 11:40:54 AM
Parent: 1d136a34c43dfe08b1b31fb15459375f3cc3e185

Files changed

index.jschanged
indexes/feed.jsadded
index.jsView
@@ -57,11 +57,10 @@
5757 module.exports = function (db, opts, keys, path) {
5858
5959 var sysDB = db.sublevel('sys')
6060 var logDB = db.sublevel('log')
61- var feedDB = db.sublevel('fd')
62- var clockDB = require('./indexes/clock')(db, {path: db.location})
63- //db.sublevel('clk')
61 + var feedDB = require('./indexes/feed')(db)
62 + var clockDB = require('./indexes/clock')(db)
6463 var lastDB = db.sublevel('lst')
6564 var indexDB = db.sublevel('idx')
6665 var appsDB = db.sublevel('app')
6766
@@ -92,19 +91,8 @@
9291 kv._value = op.value
9392 realtime(kv)
9493 }
9594
96-// add({
97-// key: [msg.author, msg.sequence], value: id,
98-// type: 'put', prefix: clockDB
99-// })
100-
101- // index my timestamp, used to generate feed.
102- add({
103- key: [msg.timestamp, msg.author], value: id,
104- type: 'put', prefix: feedDB
105- })
106-
10795 var localtime = op.timestamp = timestamp()
10896
10997 // index the latest message from each author
11098 add({
@@ -157,12 +145,8 @@
157145 })
158146 })
159147 }
160148
161- db.createFeed = function (keys, opts) {
162- return createFeed(db, keys, opts)
163- }
164-
165149 db.needsRebuild = function (cb) {
166150 sysDB.get('vmajor', function (err, dbvmajor) {
167151 dbvmajor = (dbvmajor|0) || 0
168152 cb(null, dbvmajor < getVMajor())
@@ -202,26 +186,9 @@
202186 }
203187 }
204188
205189 //TODO: eventually, this should filter out authors you do not follow.
206- db.createFeedStream = function (opts) {
207- opts = stdopts(opts)
208- //mutates opts
209- ltgt.toLtgt(opts, opts, function (value) {
210- return [value, LO]
211- }, LO, HI)
212-
213- var _keys = opts.keys
214- var _values = opts.values
215- opts.keys = false
216- opts.values = true
217-
218- return pull(
219- pl.read(feedDB, opts),
220- lookup(_keys, _values) //XXX
221- )
222- }
223-
190 + db.createFeedStream = feedDB.createFeedStream
224191 //latest was stored as author: seq
225192 //but for the purposes of replication back pressure
226193 //we need to know when we last replicated with someone.
227194 //instead store as: {sequence: seq, ts: localtime}
@@ -255,31 +222,13 @@
255222 }
256223
257224 db.lookup = lookup
258225
259- db.createHistoryStream = function (opts) {
260- return clockDB.createHistoryStream(opts)
261- }
226 + db.createHistoryStream = clockDB.createHistoryStream
262227
263- db.createUserStream = function (opts) {
264- opts = stdopts(opts)
265- //mutates opts
266- ltgt.toLtgt(opts, opts, function (value) {
267- return [opts.id, value]
268- }, LO, HI)
269- var _keys = opts.keys
270- var _values = opts.values
228 + db.createUserStream = clockDB.createUserStream
271229
272- opts.keys = false
273- opts.values = true
274- return pull(
275- clockDB.read(opts),
276-// pl.read(clockDB, opts),
277- lookup(_keys, _values)
278- )
279- }
280230
281-
282231 //writeStream - used in replication.
283232 db.createWriteStream = function (cb) {
284233 return pull(
285234 paramap(function (data, cb) {
@@ -540,10 +489,11 @@
540489
541490 var _close = db.close
542491
543492 db.close = function (cb) {
544- var n = 2
493 + var n = 3
545494 clockDB.close(next)
495 + feedDB.close(next)
546496 _close.call(db, next)
547497 function next (err) {
548498 if(n < 0) return
549499 if(err) return n = -1, cb(err)
@@ -556,13 +506,4 @@
556506 }
557507
558508
559509
560-
561-
562-
563-
564-
565-
566-
567-
568-
indexes/feed.jsView
@@ -1,0 +1,45 @@
1 +var Follower = require('../follower')
2 +var pull = require('pull-stream')
3 +var path = require('path')
4 +var ltgt = require('ltgt')
5 +var u = require('../util')
6 +
7 +module.exports = function (db) {
8 +
9 + var indexPath = path.join(db.location, 'feed')
10 + var index = Follower(db, indexPath, 1, function (data) {
11 + if(data.sync) return
12 + return {
13 + key: [data.value.timestamp, data.value.author],
14 + value: data.key, type: 'put'
15 + }
16 + })
17 +
18 + index.createFeedStream = function (opts) {
19 + opts = u.options(opts)
20 + //mutates opts
21 + ltgt.toLtgt(opts, opts, function (value) {
22 + return [value, u.lo]
23 + }, u.lo, u.hi)
24 +
25 + var _keys = opts.keys
26 + var _values = opts.values
27 + opts.keys = false
28 + opts.values = true
29 +
30 + return pull(
31 + index.read(opts),
32 + pull.through(console.log),
33 + db.lookup(_keys, _values) //XXX
34 + )
35 + }
36 +
37 + return index
38 +
39 +}
40 +
41 +
42 +
43 +
44 +
45 +

Built with git-ssb-web