mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 18:36:36 +00:00
streams: Add LazySet for subscribers.
This defers O(N*S) operations, where
N = number of streams
S = number of subscribers per stream
In many cases we never do an O(N) operation on
a stream. Exceptions include:
- checking stream links from the compose box
- editing a stream
- adding members to a newly added stream
An operation that used to be O(N)--computing
the number of subscribers--is now O(1), and we
don't even pay O(N) on a one-time basis to
compute it (not counting the cost to build the
array from JSON, but we have to do that).
This commit is contained in:
@@ -9,6 +9,8 @@ const noop = function () {};
|
||||
set_global('$', global.make_zjquery());
|
||||
set_global('i18n', global.stub_i18n);
|
||||
|
||||
const LazySet = zrequire('lazy_set.js').LazySet;
|
||||
|
||||
const _navigator = {
|
||||
platform: '',
|
||||
};
|
||||
@@ -1328,13 +1330,13 @@ run_test('on_events', () => {
|
||||
(function test_stream_name_completed_triggered() {
|
||||
const handler = $(document).get_on_handler('streamname_completed.zulip');
|
||||
stream_data.add_sub(compose_state.stream_name(), {
|
||||
subscribers: Dict.from_array([1, 2]),
|
||||
subscribers: LazySet([1, 2]),
|
||||
});
|
||||
|
||||
let data = {
|
||||
stream: {
|
||||
name: 'Denmark',
|
||||
subscribers: Dict.from_array([1, 2, 3]),
|
||||
subscribers: LazySet([1, 2, 3]),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1379,7 +1381,7 @@ run_test('on_events', () => {
|
||||
stream: {
|
||||
invite_only: true,
|
||||
name: 'Denmark',
|
||||
subscribers: Dict.from_array([1]),
|
||||
subscribers: LazySet([1]),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ zrequire('marked', 'third/marked/lib/marked');
|
||||
const actual_pygments_data = zrequire('actual_pygments_data', 'generated/pygments_data');
|
||||
zrequire('settings_org');
|
||||
const th = zrequire('typeahead_helper');
|
||||
const LazySet = zrequire('lazy_set.js').LazySet;
|
||||
|
||||
stream_data.create_streams([
|
||||
{name: 'Dev', subscribed: true, color: 'blue', stream_id: 1},
|
||||
@@ -24,13 +25,9 @@ stream_data.create_streams([
|
||||
]);
|
||||
|
||||
run_test('sort_streams', () => {
|
||||
const popular = {num_items: function () {
|
||||
return 10;
|
||||
}};
|
||||
const popular = LazySet([1, 2, 3, 4, 5, 6]);
|
||||
|
||||
const unpopular = {num_items: function () {
|
||||
return 2;
|
||||
}};
|
||||
const unpopular = LazySet([1]);
|
||||
|
||||
let test_streams = [
|
||||
{name: 'Dev', pin_to_top: false, subscribers: unpopular, subscribed: true},
|
||||
|
||||
Reference in New Issue
Block a user