git ssb

7+

dinoworm 🐛 / patchcore



Commit 1a1e663d5199d324799f97f1faf6385ae860577c

extract and expose `feed.pull.unique` out of `feed.pull.rollup`

Matt McKegg committed on 12/4/2017, 5:40:31 AM
Parent: ba518865234ed63cae50900c6ee8404aa6686cfa

Files changed

feed/pull/rollup.jschanged
feed/pull/unique.jsadded
feed/pull/rollup.jsView
@@ -1,8 +1,4 @@
1-// read stream to get events
2-// for each item, check to see if already rendered root
3-// accept prioritized list (render these first)
4-
51 var pull = require('pull-stream')
62 var nest = require('depnest')
73 var HLRU = require('hashlru')
84
@@ -11,9 +7,10 @@
117 'sbot.async.get': 'first',
128 'message.sync.isBlocked': 'first',
139 'message.sync.root': 'first',
1410 'message.sync.unbox': 'first',
15- 'feed.pull.withReplies': 'first'
11 + 'feed.pull.withReplies': 'first',
12 + 'feed.pull.unique': 'first'
1613 })
1714
1815 exports.gives = nest('feed.pull.rollup', true)
1916
@@ -22,9 +19,8 @@
2219 // not really big enough for multiple refresh cycles
2320 var cache = HLRU(100)
2421
2522 return nest('feed.pull.rollup', function (rootFilter) {
26- var seen = new Set()
2723 return pull(
2824 pull.map(msg => {
2925 if (msg.value) {
3026 var root = api.message.sync.root(msg)
@@ -37,20 +33,9 @@
3733 }
3834 }),
3935
4036 // UNIQUE
41- pull.filter(idOrMsg => {
42- if (idOrMsg) {
43- if (idOrMsg.key) idOrMsg = idOrMsg.key
44- if (typeof idOrMsg === 'string') {
45- var key = idOrMsg
46- if (!seen.has(key)) {
47- seen.add(key)
48- return true
49- }
50- }
51- }
52- }),
37 + api.feed.pull.unique(),
5338
5439 // LOOKUP (if needed)
5540 pull.asyncMap((keyOrMsg, cb) => {
5641 if (keyOrMsg.value) {
feed/pull/unique.jsView
@@ -1,0 +1,31 @@
1 +var pull = require('pull-stream')
2 +var nest = require('depnest')
3 +
4 +exports.needs = nest({
5 + 'backlinks.obs.for': 'first',
6 + 'sbot.async.get': 'first',
7 + 'message.sync.isBlocked': 'first',
8 + 'message.sync.root': 'first',
9 + 'message.sync.unbox': 'first',
10 + 'feed.pull.withReplies': 'first'
11 +})
12 +
13 +exports.gives = nest('feed.pull.unique', true)
14 +
15 +exports.create = function (api) {
16 + return nest('feed.pull.unique', function (rootFilter) {
17 + var seen = new Set()
18 + return pull.filter(idOrMsg => {
19 + if (idOrMsg) {
20 + if (idOrMsg.key) idOrMsg = idOrMsg.key
21 + if (typeof idOrMsg === 'string') {
22 + var key = idOrMsg
23 + if (!seen.has(key)) {
24 + seen.add(key)
25 + return true
26 + }
27 + }
28 + }
29 + })
30 + })
31 +}

Built with git-ssb-web