refactor: Extract peer_data.js.

This de-clutters stream_data a bit.  Since our
peer data is our biggest performance concern,
I want to contain any optimizations to a fairly
well-focused module.

The name `peer_data` is a bit of a compromise,
since we already have `subs.js` and we use
`sub` as a variable name for stream records
throughout our code, but it's consistent with
our event nomenclature (peer/add, peer/remove)
and it's short while still being fairly easy
to find with grep.
This commit is contained in:
Steve Howell
2021-01-12 20:38:01 +00:00
committed by Tim Abbott
parent 5c2f6321f2
commit 6cc880c858
17 changed files with 269 additions and 217 deletions

View File

@@ -1,5 +1,7 @@
"use strict";
const peer_data = require("./peer_data");
function display_pill(sub) {
return "#" + sub.name + ": " + sub.subscriber_count + " users";
}
@@ -39,7 +41,7 @@ function get_user_ids_from_subs(items) {
for (const item of items) {
// only some of our items have streams (for copy-from-stream)
if (item.stream_id !== undefined) {
user_ids = user_ids.concat(stream_data.get_subscribers(item.stream_id));
user_ids = user_ids.concat(peer_data.get_subscribers(item.stream_id));
}
}
return user_ids;