Commit d3e75c0a69e9cd486c63267e3e63786761c34c90
cache messages loaded via createLogStream
Dominic Tarr committed on 8/4/2016, 1:50:50 AMParent: 473ab796d9ba662aa1f1665d60c10838dc0c35d9
Files changed
sbot-api.js | changed |
sbot-api.js | ||
---|---|---|
@@ -27,8 +27,11 @@ | ||
27 | 27 | var createFeed = require('ssb-feed') |
28 | 28 | var keys = require('./keys') |
29 | 29 | var ssbKeys = require('ssb-keys') |
30 | 30 | |
31 | + | |
32 | +var cache = CACHE = {} | |
33 | + | |
31 | 34 | module.exports = function () { |
32 | 35 | var opts = createConfig() |
33 | 36 | var sbot = null |
34 | 37 | var connection_status = [] |
@@ -102,15 +105,24 @@ | ||
102 | 105 | sbot_query: rec.source(function (query) { |
103 | 106 | return sbot.query.read(query) |
104 | 107 | }), |
105 | 108 | sbot_log: rec.source(function (opts) { |
106 | - return sbot.createLogStream(opts) | |
109 | + return pull( | |
110 | + sbot.createLogStream(opts), | |
111 | + pull.through(function (e) { | |
112 | + CACHE[e.key] = CACHE[e.key] || e.value | |
113 | + }) | |
114 | + ) | |
107 | 115 | }), |
108 | 116 | sbot_user_feed: rec.source(function (opts) { |
109 | 117 | return sbot.createUserStream(opts) |
110 | 118 | }), |
111 | 119 | sbot_get: rec.async(function (key, cb) { |
112 | - sbot.get(key, cb) | |
120 | + if(CACHE[key]) cb(null, CACHE[key]) | |
121 | + sbot.get(key, function (err, value) { | |
122 | + if(err) return cb(err) | |
123 | + cb(null, CACHE[key] = value) | |
124 | + }) | |
113 | 125 | }), |
114 | 126 | sbot_publish: rec.async(function (content, cb) { |
115 | 127 | if(content.recps) |
116 | 128 | content = ssbKeys.box(content, content.recps.map(function (e) { |
@@ -136,4 +148,6 @@ | ||
136 | 148 | }) |
137 | 149 | } |
138 | 150 | } |
139 | 151 | |
152 | + | |
153 | + |
Built with git-ssb-web