git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 61a89f2614a9e41e661b0fca3162cd220b9c1b8e

feed-summary: fix pressure release (stop stalling), fix profile view missing items

Matt McKegg committed on 11/1/2016, 10:06:38 PM
Parent: c3ac1113d78826196361985ac8714e115d92deb9

Files changed

lib/feed-summary.jschanged
lib/feed-summary.jsView
@@ -23,24 +23,30 @@
2323 pull.collect((err, values) => {
2424 if (err) throw err
2525 if (!values.length) {
2626 done = true
27+ pushable.end()
28+ if (!returned) cb && cb()
29+ returned = true
2730 } else {
2831 var fromTime = last && last.timestamp || Date.now()
29- groupMessages(values, fromTime, bumpFilter).forEach(v => pushable.push(v))
3032 last = values[values.length - 1]
33+ groupMessages(values, fromTime, bumpFilter, (err, result) => {
34+ if (err) return cb(err)
35+ result.forEach(v => pushable.push(v))
36+ pushable.end()
37+ if (!returned) cb && cb()
38+ returned = true
39+ })
3140 }
32- pushable.end()
33- if (!returned) cb && cb()
34- returned = true
3541 })
3642 )
3743 }
3844 return pushable
3945 })
4046 }
4147
42-function groupMessages (messages, fromTime, bumpFilter) {
48+function groupMessages (messages, fromTime, bumpFilter, cb) {
4349 var follows = {}
4450 var messageUpdates = {}
4551 reverseForEach(messages, function (msg) {
4652 if (!msg.value) return
@@ -79,41 +85,41 @@
7985 group.channel = group.channel || msg.value.content.channel
8086
8187 // only bump when filter passes
8288 if (!bumpFilter || bumpFilter(msg, group)) {
83- group.updated = msg.timestamp
89+ group.updated = msg.timestamp || msg.value.sequence
8490 }
8591 } else {
8692 const group = ensureMessage(msg.key, messageUpdates)
8793 group.fromTime = fromTime
8894 group.lastUpdateType = 'post'
89- group.updated = msg.timestamp
95+ group.updated = msg.timestamp || msg.value.sequence
9096 group.author = msg.value.author
9197 group.channel = msg.value.content.channel
9298 group.message = msg
9399 }
94100 }
101+ }, () => {
102+ var result = []
103+ Object.keys(follows).forEach((key) => {
104+ if (follows[key].updated) {
105+ SortedArray.add(result, follows[key], compareUpdated)
106+ }
107+ })
108+ Object.keys(messageUpdates).forEach((key) => {
109+ if (messageUpdates[key].updated) {
110+ SortedArray.add(result, messageUpdates[key], compareUpdated)
111+ }
112+ })
113+ cb(null, result)
95114 })
96-
97- var result = []
98- Object.keys(follows).forEach((key) => {
99- if (follows[key].updated) {
100- SortedArray.add(result, follows[key], compareUpdated)
101- }
102- })
103- Object.keys(messageUpdates).forEach((key) => {
104- if (messageUpdates[key].updated) {
105- SortedArray.add(result, messageUpdates[key], compareUpdated)
106- }
107- })
108- return result
109115 }
110116
111117 function compareUpdated (a, b) {
112118 return b.updated - a.updated
113119 }
114120
115-function reverseForEach (items, fn) {
121+function reverseForEach (items, fn, cb) {
116122 var i = items.length - 1
117123 var start = Date.now()
118124 nextBatch()
119125
@@ -124,8 +130,10 @@
124130 }
125131
126132 if (i > 0) {
127133 setImmediate(nextBatch)
134+ } else {
135+ cb && cb()
128136 }
129137 }
130138 }
131139
@@ -145,9 +153,9 @@
145153 id: id
146154 }
147155 }
148156 group.contacts.add(c.contact)
149- group.updated = msg.timestamp
157+ group.updated = msg.timestamp || msg.value.sequence
150158 } else {
151159 if (group) {
152160 group.contacts.delete(c.contact)
153161 if (!group.contacts.size) {

Built with git-ssb-web