refactor: Extract bulk functions to add/remove peers.

We also streamline some of the error handling code
by doing everything up front.  This will prevent
scenarios where a single bad stream_id/user_id causes a
bunch of the same warnings in an inner loop.
This commit is contained in:
Steve Howell
2021-01-27 14:54:06 +00:00
committed by Tim Abbott
parent e820c43b77
commit 2edfdb4ff8
5 changed files with 83 additions and 79 deletions

View File

@@ -225,6 +225,25 @@ exports.get_sub_by_id = function (stream_id) {
return subs_by_stream_id.get(stream_id);
};
exports.validate_stream_ids = function (stream_ids) {
const good_ids = [];
const bad_ids = [];
for (const stream_id of stream_ids) {
if (subs_by_stream_id.has(stream_id)) {
good_ids.push(stream_id);
} else {
bad_ids.push(stream_id);
}
}
if (bad_ids.length > 0) {
blueslip.warn(`We have untracked stream_ids: ${bad_ids}`);
}
return good_ids;
};
exports.get_stream_id = function (name) {
// Note: Only use this function for situations where
// you are comfortable with a user dealing with an