Bug 1371721 - Keep logging repeated messages even when we reached the log-limit. r=nchevobbe
MozReview-Commit-ID: J0BXOay3huU
--- a/devtools/client/webconsole/new-console-output/reducers/messages.js
+++ b/devtools/client/webconsole/new-console-output/reducers/messages.js
@@ -146,28 +146,33 @@ function messages(state = new MessageSta
let newState;
switch (action.type) {
case constants.MESSAGES_ADD:
newState = state;
// Preemptively remove messages that will never be rendered
let list = [];
let prunableCount = 0;
+ let lastMessageRepeatId = -1;
for (let i = action.messages.length - 1; i >= 0; i--) {
- if (!action.messages[i].groupId && !isGroupType(action.messages[i].type) &&
- action.messages[i].type !== MESSAGE_TYPE.END_GROUP) {
+ let message = action.messages[i];
+ if (!message.groupId && !isGroupType(message.type) &&
+ message.type !== MESSAGE_TYPE.END_GROUP) {
prunableCount++;
- // Once we've added the max number of messages that can be added stop.
- // TODO: what about repeats?
- if (prunableCount <= logLimit) {
+ // Once we've added the max number of messages that can be added, stop.
+ // Except for repeated messages, where we keep adding over the limit.
+ if (prunableCount <= logLimit || message.repeatId == lastMessageRepeatId) {
list.unshift(action.messages[i]);
+ } else {
+ break;
}
} else {
- list.unshift(action.messages[i]);
+ list.unshift(message);
}
+ lastMessageRepeatId = message.repeatId;
}
list.forEach(message => {
newState = addMessage(newState, filtersState, prefsState, message);
});
return limitTopLevelMessageCount(newState, logLimit);
--- a/devtools/client/webconsole/new-console-output/test/store/messages.test.js
+++ b/devtools/client/webconsole/new-console-output/test/store/messages.test.js
@@ -752,9 +752,40 @@ describe("Message reducer:", () => {
expect(table.get(id2)).toBe(tableData2);
// This addition will remove the second table message.
dispatch(actions.messageAdd(stubPackets.get("console.log('foobar', 'test')")));
expect(getAllMessagesTableDataById(getState()).size).toBe(0);
});
});
+
+ describe("messagesAdd", () => {
+ it("still log repeated message over logLimit, but only repeated ones", () => {
+ // Log two distinct messages
+ const key1 = "console.log('foobar', 'test')";
+ const key2 = "console.log(undefined)";
+ const { dispatch, getState } = setupStore([key1, key2], null, {
+ logLimit: 2
+ });
+
+ // Then repeat the last one two times and log the first one again
+ const packet1 = clonePacket(stubPackets.get(key2));
+ const packet2 = clonePacket(stubPackets.get(key2));
+ const packet3 = clonePacket(stubPackets.get(key1));
+
+ // Repeat ID must be the same even if the timestamp is different.
+ packet1.message.timeStamp = 1;
+ packet2.message.timeStamp = 2;
+ packet3.message.timeStamp = 3;
+ dispatch(actions.messagesAdd([packet1, packet2, packet3]));
+
+ // There is still only two messages being logged,
+ const messages = getAllMessagesById(getState());
+ expect(messages.size).toBe(2);
+
+ // the second one being repeated 3 times
+ const repeat = getAllRepeatById(getState());
+ expect(repeat[messages.first().id]).toBe(3);
+ expect(repeat[messages.last().id]).toBe(undefined);
+ });
+ });
});