mirror of
https://github.com/zulip/zulip.git
synced 2025-11-17 12:21:58 +00:00
Avoid reloading subscribers when opening Streams page.
For a large domain like HS, we were pulling back about 100k of text with subscriber emails when we opened the Streams page. This was unnecessary, as the subscribers aren't shown until you expand the stream, and there's already an AJAX call. (imported from commit 69b83d769030d87318acefc364ac6ff3a2ec3605)
This commit is contained in:
@@ -43,6 +43,10 @@ exports.subscribed_streams = function () {
|
|||||||
return _.pluck(subscribed_streams(), 'name');
|
return _.pluck(subscribed_streams(), 'name');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.all_subs = function () {
|
||||||
|
return stream_info.values();
|
||||||
|
};
|
||||||
|
|
||||||
exports.get_colors = function () {
|
exports.get_colors = function () {
|
||||||
return _.pluck(subscribed_streams(), 'color');
|
return _.pluck(subscribed_streams(), 'color');
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -393,38 +393,17 @@ exports.reload_subscriptions = function (opts) {
|
|||||||
exports.setup_page = function () {
|
exports.setup_page = function () {
|
||||||
util.make_loading_indicator($('#subs_page_loading_indicator'));
|
util.make_loading_indicator($('#subs_page_loading_indicator'));
|
||||||
|
|
||||||
function populate_and_fill(data_for_streams, subscription_data) {
|
function populate_and_fill(data_for_streams) {
|
||||||
var all_streams = [];
|
|
||||||
var our_subs = [];
|
|
||||||
var sub_rows = [];
|
var sub_rows = [];
|
||||||
|
|
||||||
/* arguments are [ "success", statusText, jqXHR ] */
|
_.each(data_for_streams.streams, function (stream) {
|
||||||
if (data_for_streams.length > 2 && data_for_streams[2]) {
|
var sub = stream_data.get_sub(stream.name);
|
||||||
var stream_response = JSON.parse(data_for_streams[2].responseText);
|
if (!sub) {
|
||||||
_.each(stream_response.streams, function (stream) {
|
sub = create_sub(stream.name, {subscribed: false});
|
||||||
all_streams.push(stream.name);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (subscription_data.length > 2 && subscription_data[2]) {
|
|
||||||
var subs_response = JSON.parse(subscription_data[2].responseText);
|
|
||||||
our_subs = subs_response.subscriptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
// All streams won't contain invite-only streams,
|
|
||||||
// or anything at all if should_list_all_streams() is false
|
|
||||||
_.each(our_subs, function (stream) {
|
|
||||||
if (_.indexOf(all_streams, stream.name) === -1) {
|
|
||||||
all_streams.push(stream.name);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
populate_subscriptions(our_subs, true);
|
_.each(stream_data.all_subs(), function (sub) {
|
||||||
|
|
||||||
all_streams.forEach(function (stream) {
|
|
||||||
var sub = stream_data.get_sub(stream);
|
|
||||||
if (!sub) {
|
|
||||||
sub = create_sub(stream, {subscribed: false});
|
|
||||||
}
|
|
||||||
sub = _.extend(sub, {'allow_rename': page_params.show_admin});
|
sub = _.extend(sub, {'allow_rename': page_params.show_admin});
|
||||||
sub_rows.push(sub);
|
sub_rows.push(sub);
|
||||||
});
|
});
|
||||||
@@ -456,30 +435,20 @@ exports.setup_page = function () {
|
|||||||
ui.report_error("Error listing streams or subscriptions", xhr, $("#subscriptions-status"));
|
ui.report_error("Error listing streams or subscriptions", xhr, $("#subscriptions-status"));
|
||||||
}
|
}
|
||||||
|
|
||||||
var requests = [];
|
|
||||||
if (should_list_all_streams()) {
|
if (should_list_all_streams()) {
|
||||||
// This query must go first to prevent a race when we are not
|
|
||||||
// listing all streams
|
|
||||||
var req = $.ajax({
|
var req = $.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/json/get_public_streams',
|
url: '/json/get_public_streams',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
timeout: 10*1000
|
timeout: 10*1000,
|
||||||
|
success: populate_and_fill,
|
||||||
|
error: failed_listing
|
||||||
|
|
||||||
});
|
});
|
||||||
requests.push(req);
|
|
||||||
} else {
|
} else {
|
||||||
// Handing an object to $.when() means that it counts as a 'success' with the
|
populate_and_fill({streams: []});
|
||||||
// object delivered directly to the callback
|
|
||||||
requests.push({streams: []});
|
|
||||||
$('#create_stream_button').val("Subscribe");
|
$('#create_stream_button').val("Subscribe");
|
||||||
}
|
}
|
||||||
|
|
||||||
requests.push(exports.reload_subscriptions({custom_callbacks: true}));
|
|
||||||
|
|
||||||
// Trigger finished callback when:
|
|
||||||
// * Both AJAX requests are finished, if we sent themm both
|
|
||||||
// * Just one AJAX is finished if should_list_all_streams() is false
|
|
||||||
$.when.apply(this, requests).then(populate_and_fill, failed_listing);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.update_subscription_properties = function (stream_name, property, value) {
|
exports.update_subscription_properties = function (stream_name, property, value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user