mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
attachments: Stop fetching attachments in / endpoint.
We only use this data in a rarely-used settings screen, and it can be large after years of posting screenshots. So optimize the performance of / by just loading these data when we actually visit the page. This saves about 300ms of runtime for loading the home view for my user account on chat.zulip.org.
This commit is contained in:
@@ -33,10 +33,8 @@ function bytes_to_size(bytes, kb_with_1024_bytes) {
|
||||
return size + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
exports.set_up_attachments = function () {
|
||||
// The settings page must be rendered before this function gets called.
|
||||
|
||||
var attachments = page_params.attachments;
|
||||
function render_attachments_ui(attachments) {
|
||||
_.each(attachments, function (attachment) {
|
||||
var time = new XDate(attachment.create_time);
|
||||
attachment.create_time_str = timerender.render_now(time).time_str;
|
||||
@@ -78,8 +76,6 @@ exports.set_up_attachments = function () {
|
||||
return -1;
|
||||
});
|
||||
|
||||
|
||||
|
||||
ui.set_up_scrollbar(uploaded_files_table.closest(".progressive-table-wrapper"));
|
||||
|
||||
uploaded_files_table.empty();
|
||||
@@ -93,6 +89,26 @@ exports.set_up_attachments = function () {
|
||||
row.remove();
|
||||
delete_attachments($(this).data('attachment'));
|
||||
});
|
||||
}
|
||||
|
||||
exports.set_up_attachments = function () {
|
||||
// The settings page must be rendered before this function gets called.
|
||||
|
||||
var status = $('#delete-upload-status');
|
||||
loading.make_indicator($('#attachments_loading_indicator'), {text: 'Loading...'});
|
||||
|
||||
channel.get({
|
||||
url: "/json/attachments",
|
||||
idempotent: true,
|
||||
success: function (data) {
|
||||
loading.destroy_indicator($('#attachments_loading_indicator'));
|
||||
render_attachments_ui(data.attachments);
|
||||
},
|
||||
error: function (xhr) {
|
||||
loading.destroy_indicator($('#attachments_loading_indicator'));
|
||||
ui_report.error(i18n.t("Failed"), xhr, status);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return exports;
|
||||
|
||||
@@ -2042,6 +2042,7 @@ div.floating_recipient {
|
||||
}
|
||||
|
||||
.settings-section #admin_page_users_loading_indicator,
|
||||
.settings-section #attachments_loading_indicator,
|
||||
.settings-section #admin_page_deactivated_users_loading_indicator,
|
||||
.settings-section #admin_page_bots_loading_indicator {
|
||||
margin: 0 auto;
|
||||
|
||||
@@ -17,4 +17,5 @@
|
||||
id="uploaded_files_table" ></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div id="attachments_loading_indicator"></div>
|
||||
</div>
|
||||
|
||||
@@ -125,9 +125,6 @@ def fetch_initial_state_data(user_profile: UserProfile,
|
||||
state['custom_profile_fields'] = [f.as_dict() for f in fields]
|
||||
state['custom_profile_field_types'] = CustomProfileField.FIELD_TYPE_CHOICES
|
||||
|
||||
if want('attachments'):
|
||||
state['attachments'] = user_attachments(user_profile)
|
||||
|
||||
if want('hotspots'):
|
||||
state['hotspots'] = get_next_hotspots(user_profile)
|
||||
|
||||
|
||||
@@ -2803,11 +2803,10 @@ class FetchQueriesTest(ZulipTestCase):
|
||||
client_gravatar=False,
|
||||
)
|
||||
|
||||
self.assert_length(queries, 30)
|
||||
self.assert_length(queries, 29)
|
||||
|
||||
expected_counts = dict(
|
||||
alert_words=0,
|
||||
attachments=1,
|
||||
custom_profile_fields=1,
|
||||
default_streams=1,
|
||||
default_stream_groups=1,
|
||||
|
||||
@@ -45,7 +45,6 @@ class HomeTest(ZulipTestCase):
|
||||
# Keep this list sorted!!!
|
||||
expected_keys = [
|
||||
"alert_words",
|
||||
"attachments",
|
||||
"avatar_source",
|
||||
"avatar_url",
|
||||
"avatar_url_medium",
|
||||
@@ -198,7 +197,7 @@ class HomeTest(ZulipTestCase):
|
||||
with patch('zerver.lib.cache.cache_set') as cache_mock:
|
||||
result = self._get_home_page(stream='Denmark')
|
||||
|
||||
self.assert_length(queries, 42)
|
||||
self.assert_length(queries, 41)
|
||||
self.assert_length(cache_mock.call_args_list, 7)
|
||||
|
||||
html = result.content.decode('utf-8')
|
||||
@@ -242,7 +241,7 @@ class HomeTest(ZulipTestCase):
|
||||
result = self._get_home_page()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assert_length(cache_mock.call_args_list, 6)
|
||||
self.assert_length(queries, 39)
|
||||
self.assert_length(queries, 37)
|
||||
|
||||
@slow("Creates and subscribes 10 users in a loop. Should use bulk queries.")
|
||||
def test_num_queries_with_streams(self) -> None:
|
||||
@@ -274,7 +273,7 @@ class HomeTest(ZulipTestCase):
|
||||
with queries_captured() as queries2:
|
||||
result = self._get_home_page()
|
||||
|
||||
self.assert_length(queries2, 36)
|
||||
self.assert_length(queries2, 35)
|
||||
|
||||
# Do a sanity check that our new streams were in the payload.
|
||||
html = result.content.decode('utf-8')
|
||||
|
||||
Reference in New Issue
Block a user