зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1612571 - Store the last message id instead of computing it from the message map. r=jlast.
The id was retrieved by transforming the map into an array and getting the last element of it. This was slow and allocatiing a lot of memory when the messages Map contained a lot of elements. This patch make it so we're now storing the last message id directly in the state so we can get it in a cheaper way. Differential Revision: https://phabricator.services.mozilla.com/D62185 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
c654633e4e
Коммит
938fe1ae72
|
@ -97,6 +97,8 @@ const MessageState = overrides =>
|
|||
// Map of the form {messageId : networkInformation}
|
||||
// `networkInformation` holds request, response, totalTime, ...
|
||||
networkMessagesUpdateById: {},
|
||||
// Id of the last messages that was added.
|
||||
lastMessageId: null,
|
||||
},
|
||||
overrides
|
||||
)
|
||||
|
@ -115,6 +117,7 @@ function cloneState(state) {
|
|||
repeatById: { ...state.repeatById },
|
||||
networkMessagesUpdateById: { ...state.networkMessagesUpdateById },
|
||||
warningGroupsById: new Map(state.warningGroupsById),
|
||||
lastMessageId: state.lastMessageId,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -143,9 +146,8 @@ function addMessage(newMessage, state, filtersState, prefsState, uiState) {
|
|||
return state;
|
||||
}
|
||||
|
||||
if (newMessage.allowRepeating && messagesById.size > 0) {
|
||||
const lastMessage = messagesById.get(getLastMessageId(state));
|
||||
|
||||
const lastMessage = messagesById.get(state.lastMessageId);
|
||||
if (lastMessage && newMessage.allowRepeating && messagesById.size > 0) {
|
||||
if (
|
||||
lastMessage.repeatId === newMessage.repeatId &&
|
||||
lastMessage.groupId === currentGroup
|
||||
|
@ -155,6 +157,9 @@ function addMessage(newMessage, state, filtersState, prefsState, uiState) {
|
|||
}
|
||||
}
|
||||
|
||||
// Store the id of the message as being the last one being added.
|
||||
state.lastMessageId = newMessage.id;
|
||||
|
||||
// Add the new message with a reference to the parent group.
|
||||
const parentGroups = getParentGroups(currentGroup, groupsById);
|
||||
if (!isWarningGroup(newMessage)) {
|
||||
|
@ -1497,10 +1502,6 @@ function maybeSortVisibleMessages(
|
|||
}
|
||||
}
|
||||
|
||||
function getLastMessageId(state) {
|
||||
return Array.from(state.messagesById.keys())[state.messagesById.size - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if a given type of warning message should be grouped.
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче