Commit e7b02af84a46b3c6ce2c5b9340093fa214b9600c
throttle following, recently-update-feeds, subscribed-channels
Matt McKegg committed on 11/2/2016, 12:51:31 AMParent: 9ab01d1299a52a303ff09bb2e73ff80739328656
Files changed
modules/obs-following.js | changed |
modules/obs-recently-updated-feeds.js | changed |
modules/obs-subscribed-channels.js | changed |
modules/obs-following.js | |||
---|---|---|---|
@@ -3,8 +3,9 @@ | |||
3 | 3 … | var MutantPullReduce = require('../lib/mutant-pull-reduce') | |
4 | 4 … | var plugs = require('patchbay/plugs') | |
5 | 5 … | var sbot_user_feed = plugs.first(exports.sbot_user_feed = []) | |
6 | 6 … | var cache = {} | |
7 … | +var throttle = require('@mmckegg/mutant/throttle') | ||
7 | 8 … | ||
8 | 9 … | exports.obs_following = function (userId) { | |
9 | 10 … | if (cache[userId]) { | |
10 | 11 … | return cache[userId] | |
@@ -32,12 +33,15 @@ | |||
32 | 33 … | startValue: new Set(), | |
33 | 34 … | nextTick: true | |
34 | 35 … | }) | |
35 | 36 … | ||
36 | - result.has = function (value) { | ||
37 | - return computed(result, x => x.has(value)) | ||
37 … | + var instance = throttle(result, 2000) | ||
38 … | + instance.sync = result.sync | ||
39 … | + | ||
40 … | + instance.has = function (value) { | ||
41 … | + return computed(instance, x => x.has(value)) | ||
38 | 42 … | } | |
39 | 43 … | ||
40 | - cache[userId] = result | ||
41 | - return result | ||
44 … | + cache[userId] = instance | ||
45 … | + return instance | ||
42 | 46 … | } | |
43 | 47 … | } |
modules/obs-recently-updated-feeds.js | ||
---|---|---|
@@ -3,8 +3,9 @@ | ||
3 | 3 … | var computed = require('@mmckegg/mutant/computed') |
4 | 4 … | var MutantPullReduce = require('../lib/mutant-pull-reduce') |
5 | 5 … | var plugs = require('patchbay/plugs') |
6 | 6 … | var sbot_log = plugs.first(exports.sbot_log = []) |
7 … | +var throttle = require('@mmckegg/mutant/throttle') | |
7 | 8 … | var hr = 60 * 60 * 1000 |
8 | 9 … | |
9 | 10 … | exports.obs_recently_updated_feeds = function (limit) { |
10 | 11 … | var stream = pull( |
@@ -23,10 +24,13 @@ | ||
23 | 24 … | startValue: new Set(), |
24 | 25 … | nextTick: true |
25 | 26 … | }) |
26 | 27 … | |
27 | - result.has = function (value) { | |
28 | - return computed(result, x => x.has(value)) | |
28 … | + var instance = throttle(result, 2000) | |
29 … | + instance.sync = result.sync | |
30 … | + | |
31 … | + instance.has = function (value) { | |
32 … | + return computed(instance, x => x.has(value)) | |
29 | 33 … | } |
30 | 34 … | |
31 | - return result | |
35 … | + return instance | |
32 | 36 … | } |
modules/obs-subscribed-channels.js | ||
---|---|---|
@@ -3,8 +3,9 @@ | ||
3 | 3 … | var MutantPullReduce = require('../lib/mutant-pull-reduce') |
4 | 4 … | var plugs = require('patchbay/plugs') |
5 | 5 … | var sbot_user_feed = plugs.first(exports.sbot_user_feed = []) |
6 | 6 … | var cache = {} |
7 … | +var throttle = require('@mmckegg/mutant/throttle') | |
7 | 8 … | |
8 | 9 … | exports.obs_subscribed_channels = function (userId) { |
9 | 10 … | if (cache[userId]) { |
10 | 11 … | return cache[userId] |
@@ -35,13 +36,15 @@ | ||
35 | 36 … | startValue: new Set(), |
36 | 37 … | nextTick: true |
37 | 38 … | }) |
38 | 39 … | |
39 | - result.has = function (value) { | |
40 | - return computed(result, x => x.has(value)) | |
40 … | + var instance = throttle(result, 2000) | |
41 … | + instance.sync = result.sync | |
42 … | + | |
43 … | + instance.has = function (value) { | |
44 … | + return computed(instance, x => x.has(value)) | |
41 | 45 … | } |
42 | 46 … | |
43 | - cache[userId] = result | |
44 | - return result | |
47 … | + cache[userId] = instance | |
48 … | + return instance | |
45 | 49 … | } |
46 | - | |
47 | 50 … | } |
Built with git-ssb-web