mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
refactor: Remove maybe_clear_subscribers().
The maybe_clear_subscribers() function was an artifact of when we used to attach subscribers to the "sub" records in stream_data.js. I think it was basically a refactoring shim, and due to some other recent cleanup, it was only used in test code. We also change how we validate stream ids. Going forward, peer_data just looks up stream_ids with the normal stream_data API when it's trying to warn about rogue stream_ids coming in. As I alluded to in an earlier commit, some of the warning code here might be overly defensive, but at least it's pretty self-contained.
This commit is contained in:
@@ -2,9 +2,6 @@ const {LazySet} = require("./lazy_set");
|
||||
const people = require("./people");
|
||||
|
||||
// This maps a stream_id to a LazySet of user_ids who are subscribed.
|
||||
// We maintain the invariant that this has keys for all all stream_ids
|
||||
// that we track in the other data structures. We intialize it during
|
||||
// clear_subscriptions.
|
||||
let stream_subscribers;
|
||||
|
||||
function assert_number(id) {
|
||||
@@ -14,14 +11,17 @@ function assert_number(id) {
|
||||
}
|
||||
|
||||
function get_user_set(stream_id) {
|
||||
assert_number(stream_id);
|
||||
|
||||
// This is an internal function to get the LazySet of users.
|
||||
// We create one on the fly as necessary, but we warn in that case.
|
||||
assert_number(stream_id);
|
||||
|
||||
if (!stream_data.get_sub_by_id(stream_id)) {
|
||||
blueslip.warn("We called get_user_set for an untracked stream: " + stream_id);
|
||||
}
|
||||
|
||||
let subscribers = stream_subscribers.get(stream_id);
|
||||
|
||||
if (subscribers === undefined) {
|
||||
blueslip.warn("We called get_user_set for an untracked stream: " + stream_id);
|
||||
subscribers = new LazySet([]);
|
||||
stream_subscribers.set(stream_id, subscribers);
|
||||
}
|
||||
@@ -33,12 +33,6 @@ export function clear() {
|
||||
stream_subscribers = new Map();
|
||||
}
|
||||
|
||||
export function maybe_clear_subscribers(stream_id) {
|
||||
if (!stream_subscribers.has(stream_id)) {
|
||||
set_subscribers(stream_id, []);
|
||||
}
|
||||
}
|
||||
|
||||
export function is_subscriber_subset(stream_id1, stream_id2) {
|
||||
const sub1_set = get_user_set(stream_id1);
|
||||
const sub2_set = get_user_set(stream_id2);
|
||||
|
||||
Reference in New Issue
Block a user