mirror of https://github.com/zulip/zulip.git
server_events: Fix unnecessary call to insert_new_messages.
When we're handling a single message that was locally echoed, there will very likely be 0 messages not removed by `echo.process_from_server`, and we can skip the unnecessary call to `message_events.insert_new_messages`. This is a small performance optimization and logical simplification when sending messages.
This commit is contained in:
parent
2580965284
commit
f4aa71fc75
|
@ -103,24 +103,26 @@ function get_events_success(events) {
|
|||
messages = _.sortBy(messages, 'id');
|
||||
try {
|
||||
messages = echo.process_from_server(messages);
|
||||
_.each(messages, message_store.set_message_booleans);
|
||||
var sent_by_this_client = false;
|
||||
_.each(messages, function (msg) {
|
||||
var msg_state = sent_messages.messages[msg.local_id];
|
||||
if (msg_state) {
|
||||
// Almost every time, this message will be the
|
||||
// only one in messages, because multiple messages
|
||||
// being returned by get_events usually only
|
||||
// happens when a client is offline, but we know
|
||||
// this client just sent a message in this batch
|
||||
// of events. But in any case,
|
||||
// insert_new_messages handles multiple messages,
|
||||
// only one of which was sent by this client,
|
||||
// correctly.
|
||||
sent_by_this_client = true;
|
||||
}
|
||||
});
|
||||
message_events.insert_new_messages(messages, sent_by_this_client);
|
||||
if (messages.length > 0) {
|
||||
_.each(messages, message_store.set_message_booleans);
|
||||
var sent_by_this_client = false;
|
||||
_.each(messages, function (msg) {
|
||||
var msg_state = sent_messages.messages[msg.local_id];
|
||||
if (msg_state) {
|
||||
// Almost every time, this message will be the
|
||||
// only one in messages, because multiple messages
|
||||
// being returned by get_events usually only
|
||||
// happens when a client is offline, but we know
|
||||
// this client just sent a message in this batch
|
||||
// of events. But in any case,
|
||||
// insert_new_messages handles multiple messages,
|
||||
// only one of which was sent by this client,
|
||||
// correctly.
|
||||
sent_by_this_client = true;
|
||||
}
|
||||
});
|
||||
message_events.insert_new_messages(messages, sent_by_this_client);
|
||||
}
|
||||
} catch (ex2) {
|
||||
blueslip.error('Failed to insert new messages\n' +
|
||||
blueslip.exception_msg(ex2),
|
||||
|
|
Loading…
Reference in New Issue