Commit Graph

13 Commits

Author SHA1 Message Date
Anders Kaseorg 3ef6f6e2e2 js: Convert static/js/blueslip.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-17 08:47:15 -04:00
Steve Howell a4ab6065cd node tests: Clear data for peer_data tests. 2021-03-10 07:07:34 -05:00
Anders Kaseorg b38712d8d2 js: Convert residual require() calls to import in ES6 modules.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-02 17:06:35 -08:00
Anders Kaseorg 245d6c3a3e js: Convert static/js/stream_data.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Steve Howell 17ea215f18 minor: Remove peer_data.clear(). 2021-02-03 15:23:17 -08:00
Steve Howell 58855e8224 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.
2021-02-03 15:23:17 -08:00
Steve Howell e44e48ef20 minor: Add get_user_set call that I missed earlier.
In my recent commit to introduce get_user_set() I
inadvertently skipped one place to call it.

I also remove a return statement that was made
unnecessary by the new get_user_set() helper.
2021-02-03 15:23:17 -08:00
Steve Howell e243af531b refactor: Extract get_user_set in peer_data.
We now use the same code in all places to
get the bucket of user_ids that correspond
to a stream, and we consistently treat
a stream as having zero subscribers, not
an undefined number of subscribers, in
the hypothetical case of us asking about
a stream that we're not tracking.

The behavior for untracked streams has
always been problematic, since if a
stream is untracked, all bets are off.

So now if we don't "track" the stream,
the subscriber count is zero.  None of
our callers distinguish between undefined
and zero.

And we just consider the stream to be subscribed
by a user when add_subscriber is called,
even if we haven't been told by stream_data
to track the stream.  (We also stop
returning true/false from add_subscriber,
since only test code was looking at it.)

We protect against the most likely source
of internal-to-the-frontend bugs by adding
the assert_number() call.

We generally have to assume that the server
is sending us sensible data at page load
time, or all bets are off.

And we have good protections in place
for unknown ids in our dispatch code
for peer_add/peer_remove events.
2021-01-29 15:21:07 -08:00
Steve Howell 6c4b1183f2 node tests: Move peer_data tests to new peer_data.js. 2021-01-29 15:21:07 -08:00
Steve Howell 2edfdb4ff8 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.
2021-01-29 15:21:07 -08:00
Steve Howell 2382fa7a19 refactor: Pass stream_ids to is_subscriber_subset.
After this change all peer_data functions consistently
use stream_id rather than some "sub" object whose
data type is complicated by all sort of fields that
don't really concern how we track subscribers.
2021-01-17 10:40:17 -08:00
Steve Howell 355f44ef13 refactor: Only pass stream_id for set_subscribers.
The goal here is to make all our peer_data functions
basically work in id space.  Passing a full `sub`
to these functions is a legacy of when subscriber
info was attached to a full stream "sub" object,
but we don't care about anything sub-related
(color, description, name, etc.) when we are
dealing with subscriptions.

When callers pass in stream_id, you can be more
confident in a quick skim of the code that we're
not mutating anything in the "sub".
2021-01-17 10:40:17 -08:00
Steve Howell 6cc880c858 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.
2021-01-17 10:40:17 -08:00