Commit fdca1d25ea142fa395482e66593db66d33f6589c
add about/pull/updates cache invalidator thang!
mixmix committed on 9/27/2018, 12:16:31 AMParent: 1638374a92e57fa5d3788ab84e8b19036bbc9044
Files changed
about/pull/updates.js | added |
app/page/query.js | changed |
package-lock.json | changed |
package.json | changed |
about/pull/updates.js | ||
---|---|---|
@@ -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.js | ||
---|---|---|
@@ -3,8 +3,9 @@ | ||
3 | 3 … | const Scroller = require('mutant-scroll') |
4 | 4 … | const next = require('pull-next-query') |
5 | 5 … | const json5 = require('json5') |
6 | 6 … | const get = require('lodash/get') |
7 … | +const isEqual = require('lodash/isEqual') | |
7 | 8 … | |
8 | 9 … | exports.gives = nest({ |
9 | 10 … | 'app.html.menuItem': true, |
10 | 11 … | 'app.page.query': true |
@@ -43,9 +44,12 @@ | ||
43 | 44 … | } catch (err) { |
44 | 45 … | // console.error(err) |
45 | 46 … | return err |
46 | 47 … | } |
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) | |
48 | 52 … | }) |
49 | 53 … | |
50 | 54 … | const activateQuery = () => state.opts.set(json5.parse(resolve(state.input))) |
51 | 55 … | |
@@ -65,9 +69,10 @@ | ||
65 | 69 … | render: buildRawMsg, |
66 | 70 … | comparer: (a, b) => { |
67 | 71 … | if (a && b && a.key && b.key) return a.key === b.key |
68 | 72 … | return a === b |
69 | - } | |
73 … | + }, | |
74 … | + cb: console.error | |
70 | 75 … | }) |
71 | 76 … | }) |
72 | 77 … | ]) |
73 | 78 … | ]) |
package-lock.json | ||
---|---|---|
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.json | ||
---|---|---|
@@ -69,15 +69,16 @@ | ||
69 | 69 … | "patch-inbox": "^1.1.8", |
70 | 70 … | "patch-settings": "^1.1.2", |
71 | 71 … | "patch-suggest": "^2.0.2", |
72 | 72 … | "patchbay-book": "^1.0.8", |
73 | - "patchbay-dark-crystal": "^1.0.3", | |
73 … | + "patchbay-dark-crystal": "^1.0.5", | |
74 | 74 … | "patchbay-gatherings": "^2.0.2", |
75 | 75 … | "patchbay-poll": "^1.0.9", |
76 | 76 … | "patchbay-scry": "^1.1.2", |
77 | 77 … | "patchcore": "^1.28.1", |
78 | 78 … | "pull-abortable": "^4.1.1", |
79 | 79 … | "pull-next-query": "^1.0.0", |
80 … | + "pull-notify": "^0.1.1", | |
80 | 81 … | "pull-scroll": "^1.0.9", |
81 | 82 … | "pull-stream": "^3.6.9", |
82 | 83 … | "read-directory": "^3.0.0", |
83 | 84 … | "require-style": "^1.0.1", |
Built with git-ssb-web