git ssb

0+

cel / ssb-wikimedia



Commit 2bf1394722753ed8aff3228422571438b98fe96f

Add userId property

cel committed on 12/1/2019, 4:12:53 AM
Parent: 3f6da406d8217032f93b552b50bee8ca2384591a

Files changed

README.mdchanged
bin.jschanged
README.mdView
@@ -26,8 +26,9 @@
2626 - Property "site" refers to the Wikimedia site base URL.
2727 - Property `pageId` is a [denormalization](https://en.wikipedia.org/wiki/Denormalization) used to facilitate querying SSB for an article. It is the SSB blob hash of the values for the site property and title property, separated by a tab ("\t").
2828 - Content ("*" property in revision slots) is replaced with the id of the SSB blob containing that content, at property "link".
2929 - Property "parents" is an array of links to the latest previous message(s) of the same type for the same page containing previous revisions to the page. Any revision parent id referenced from the current message should be found in the current message or a message referenced in this parents array.
30 +- Property "userId" is added to each revision object. It is computed the same as `pageId` but for the User page of the revision author.
3031
3132 Example:
3233
3334 ```
@@ -45,8 +46,9 @@
4546 {
4647 "revid": 999999999,
4748 "parentid": 999999998,
4849 "user": "Username",
50 + "userId": "&...sha256",
4951 "timestamp": "2019-11-22T00:00:00Z",
5052 "roles": [
5153 "main"
5254 ],
bin.jsView
@@ -194,10 +194,12 @@
194194 })
195195 if (!--waiting) next()
196196 })
197197 }(api))
198 +
198199 function next() {
199200 console.log('Getting revisions...')
201 + var userHashes = {}
200202 pull(
201203 pull.values(pagesInfo),
202204 pull.asyncMap(function (pageInfo, cb) {
203205 // Calculate blob id for page URL + title, for linking
@@ -290,8 +292,23 @@
290292 })
291293 },
292294 pull.flatten(),
293295 pull.asyncMap(function (rev, cb) {
296 + // Calculate blob id for user page URL + title, for linking
297 + var hash = userHashes[rev.user]
298 + if (hash) {
299 + rev.userId = hash
300 + return cb(null, rev)
301 + }
302 + pull(
303 + pull.once(pageInfo.site + '\tUser:' + rev.user),
304 + sbot.blobs.add(function (err, hash) {
305 + rev.userId = userHashes[rev.user] = hash
306 + cb(null, rev)
307 + })
308 + )
309 + }),
310 + pull.asyncMap(function (rev, cb) {
294311 var waiting = 0
295312 for (var slot in rev.slots) (function (slot) {
296313 waiting++
297314 var slotInfo = rev.slots[slot]

Built with git-ssb-web