Commit 61a89f2614a9e41e661b0fca3162cd220b9c1b8e
feed-summary: fix pressure release (stop stalling), fix profile view missing items
Matt McKegg committed on 11/1/2016, 10:06:38 PMParent: c3ac1113d78826196361985ac8714e115d92deb9
Files changed
lib/feed-summary.js | changed |
lib/feed-summary.js | ||
---|---|---|
@@ -23,24 +23,30 @@ | ||
23 | 23 | pull.collect((err, values) => { |
24 | 24 | if (err) throw err |
25 | 25 | if (!values.length) { |
26 | 26 | done = true |
27 | + pushable.end() | |
28 | + if (!returned) cb && cb() | |
29 | + returned = true | |
27 | 30 | } else { |
28 | 31 | var fromTime = last && last.timestamp || Date.now() |
29 | - groupMessages(values, fromTime, bumpFilter).forEach(v => pushable.push(v)) | |
30 | 32 | 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 | + }) | |
31 | 40 | } |
32 | - pushable.end() | |
33 | - if (!returned) cb && cb() | |
34 | - returned = true | |
35 | 41 | }) |
36 | 42 | ) |
37 | 43 | } |
38 | 44 | return pushable |
39 | 45 | }) |
40 | 46 | } |
41 | 47 | |
42 | -function groupMessages (messages, fromTime, bumpFilter) { | |
48 | +function groupMessages (messages, fromTime, bumpFilter, cb) { | |
43 | 49 | var follows = {} |
44 | 50 | var messageUpdates = {} |
45 | 51 | reverseForEach(messages, function (msg) { |
46 | 52 | if (!msg.value) return |
@@ -79,41 +85,41 @@ | ||
79 | 85 | group.channel = group.channel || msg.value.content.channel |
80 | 86 | |
81 | 87 | // only bump when filter passes |
82 | 88 | if (!bumpFilter || bumpFilter(msg, group)) { |
83 | - group.updated = msg.timestamp | |
89 | + group.updated = msg.timestamp || msg.value.sequence | |
84 | 90 | } |
85 | 91 | } else { |
86 | 92 | const group = ensureMessage(msg.key, messageUpdates) |
87 | 93 | group.fromTime = fromTime |
88 | 94 | group.lastUpdateType = 'post' |
89 | - group.updated = msg.timestamp | |
95 | + group.updated = msg.timestamp || msg.value.sequence | |
90 | 96 | group.author = msg.value.author |
91 | 97 | group.channel = msg.value.content.channel |
92 | 98 | group.message = msg |
93 | 99 | } |
94 | 100 | } |
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) | |
95 | 114 | }) |
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 | |
109 | 115 | } |
110 | 116 | |
111 | 117 | function compareUpdated (a, b) { |
112 | 118 | return b.updated - a.updated |
113 | 119 | } |
114 | 120 | |
115 | -function reverseForEach (items, fn) { | |
121 | +function reverseForEach (items, fn, cb) { | |
116 | 122 | var i = items.length - 1 |
117 | 123 | var start = Date.now() |
118 | 124 | nextBatch() |
119 | 125 | |
@@ -124,8 +130,10 @@ | ||
124 | 130 | } |
125 | 131 | |
126 | 132 | if (i > 0) { |
127 | 133 | setImmediate(nextBatch) |
134 | + } else { | |
135 | + cb && cb() | |
128 | 136 | } |
129 | 137 | } |
130 | 138 | } |
131 | 139 | |
@@ -145,9 +153,9 @@ | ||
145 | 153 | id: id |
146 | 154 | } |
147 | 155 | } |
148 | 156 | group.contacts.add(c.contact) |
149 | - group.updated = msg.timestamp | |
157 | + group.updated = msg.timestamp || msg.value.sequence | |
150 | 158 | } else { |
151 | 159 | if (group) { |
152 | 160 | group.contacts.delete(c.contact) |
153 | 161 | if (!group.contacts.size) { |
Built with git-ssb-web