git ssb

16+

Dominic / patchbay



Commit fdca1d25ea142fa395482e66593db66d33f6589c

add about/pull/updates cache invalidator thang!

mixmix committed on 9/27/2018, 12:16:31 AM
Parent: 1638374a92e57fa5d3788ab84e8b19036bbc9044

Files changed

about/pull/updates.jsadded
app/page/query.jschanged
package-lock.jsonchanged
package.jsonchanged
about/pull/updates.jsView
@@ -1,0 +1,65 @@
1 +const nest = require('depnest')
2 +const pull = require('pull-stream')
3 +const Notify = require('pull-notify')
4 +const { isMsg, isFeed } = require('ssb-ref')
5 +
6 +exports.gives = nest('about.pull.updates')
7 +
8 +exports.needs = nest({
9 + 'keys.sync.id': 'first',
10 + 'message.obs.likes': 'first',
11 + 'sbot.pull.stream': 'first'
12 +})
13 +
14 +exports.create = (api) => {
15 + const cache = {}
16 + var listening = false
17 +
18 + return nest('about.pull.updates', updates)
19 +
20 + function updates (key) {
21 + if (!(isMsg(key) || isFeed(key))) throw new Error(`about.pull.updates expects a valid message/ feed key, got ${key}`)
22 + startListening()
23 +
24 + if (!cache[key]) cache[key] = Notify()
25 + return cache[key].listen()
26 + }
27 +
28 + function startListening () {
29 + if (listening) return
30 +
31 + const opts = {
32 + live: true,
33 + old: false,
34 + query: [{
35 + $filter: {
36 + value: {
37 + timestamp: { $gt: 0 },
38 + content: {
39 + type: 'about',
40 + about: { $truthy: true }
41 + }
42 + }
43 + }
44 + }, {
45 + $map: {
46 + about: ['value', 'content', 'about']
47 + }
48 + }]
49 + }
50 + pull(
51 + api.sbot.pull.stream(server => server.query.read(opts)),
52 + pull.filter(m => !m.sync),
53 + pull.drain(
54 + ({ about }) => {
55 + if (!cache[about]) return
56 +
57 + cache[about](1) // emit a minimal update!
58 + },
59 + (err) => console.error(err)
60 + )
61 + )
62 +
63 + listening = true
64 + }
65 +}
app/page/query.jsView
@@ -3,8 +3,9 @@
33 const Scroller = require('mutant-scroll')
44 const next = require('pull-next-query')
55 const json5 = require('json5')
66 const get = require('lodash/get')
7 +const isEqual = require('lodash/isEqual')
78
89 exports.gives = nest({
910 'app.html.menuItem': true,
1011 'app.page.query': true
@@ -43,9 +44,12 @@
4344 } catch (err) {
4445 // console.error(err)
4546 return err
4647 }
47- if (isValidOpts(newOpts)) state.opts.set(newOpts)
48 + // NOTE - this is the piece which auto-runs the quers
49 + if (!isValidOpts(newOpts)) return
50 + if (isEqual(resolve(state.opts), newOpts)) return
51 + state.opts.set(newOpts)
4852 })
4953
5054 const activateQuery = () => state.opts.set(json5.parse(resolve(state.input)))
5155
@@ -65,9 +69,10 @@
6569 render: buildRawMsg,
6670 comparer: (a, b) => {
6771 if (a && b && a.key && b.key) return a.key === b.key
6872 return a === b
69- }
73 + },
74 + cb: console.error
7075 })
7176 })
7277 ])
7378 ])
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 315117 bytes
New file size: 315113 bytes
package.jsonView
@@ -69,15 +69,16 @@
6969 "patch-inbox": "^1.1.8",
7070 "patch-settings": "^1.1.2",
7171 "patch-suggest": "^2.0.2",
7272 "patchbay-book": "^1.0.8",
73- "patchbay-dark-crystal": "^1.0.3",
73 + "patchbay-dark-crystal": "^1.0.5",
7474 "patchbay-gatherings": "^2.0.2",
7575 "patchbay-poll": "^1.0.9",
7676 "patchbay-scry": "^1.1.2",
7777 "patchcore": "^1.28.1",
7878 "pull-abortable": "^4.1.1",
7979 "pull-next-query": "^1.0.0",
80 + "pull-notify": "^0.1.1",
8081 "pull-scroll": "^1.0.9",
8182 "pull-stream": "^3.6.9",
8283 "read-directory": "^3.0.0",
8384 "require-style": "^1.0.1",

Built with git-ssb-web