mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 20:26:24 +00:00
Improve performance of _getLeftPaneList (#3398)
* Improve efficiency of conversation sorting in getLeftPaneLists - Sort conversations and archivedConversations separately, without items that had falsey activeAt - Don't convert conversation titles to lowercase before comparing: collator.compare() is case-insensitive anyway. * Enable caching for format() in PhoneNumber
This commit is contained in:
committed by
Scott Nonnenberg
parent
9376dba806
commit
6150c3dcc0
@@ -91,11 +91,11 @@ export const _getConversationComparator = (
|
||||
const leftTitle = getConversationTitle(left, {
|
||||
i18n,
|
||||
ourRegionCode,
|
||||
}).toLowerCase();
|
||||
});
|
||||
const rightTitle = getConversationTitle(right, {
|
||||
i18n,
|
||||
ourRegionCode,
|
||||
}).toLowerCase();
|
||||
});
|
||||
|
||||
return collator.compare(leftTitle, rightTitle);
|
||||
};
|
||||
@@ -114,15 +114,13 @@ export const _getLeftPaneLists = (
|
||||
conversations: Array<ConversationType>;
|
||||
archivedConversations: Array<ConversationType>;
|
||||
} => {
|
||||
const values = Object.values(lookup);
|
||||
const sorted = values.sort(comparator);
|
||||
|
||||
const conversations: Array<ConversationType> = [];
|
||||
const archivedConversations: Array<ConversationType> = [];
|
||||
|
||||
const max = sorted.length;
|
||||
const values = Object.values(lookup);
|
||||
const max = values.length;
|
||||
for (let i = 0; i < max; i += 1) {
|
||||
let conversation = sorted[i];
|
||||
let conversation = values[i];
|
||||
if (!conversation.activeAt) {
|
||||
continue;
|
||||
}
|
||||
@@ -141,6 +139,9 @@ export const _getLeftPaneLists = (
|
||||
}
|
||||
}
|
||||
|
||||
conversations.sort(comparator);
|
||||
archivedConversations.sort(comparator);
|
||||
|
||||
return { conversations, archivedConversations };
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { instance, PhoneNumberFormat } from '../util/libphonenumberInstance';
|
||||
import memoizee from 'memoizee';
|
||||
|
||||
export function format(
|
||||
function _format(
|
||||
phoneNumber: string,
|
||||
options: {
|
||||
ourRegionCode: string;
|
||||
@@ -21,6 +22,14 @@ export function format(
|
||||
}
|
||||
}
|
||||
|
||||
export const format = memoizee(_format, {
|
||||
primitive: true,
|
||||
// Convert the arguments to a unique string, required for primitive mode.
|
||||
normalizer: function(args) {
|
||||
return JSON.stringify(args);
|
||||
}
|
||||
});
|
||||
|
||||
export function parse(
|
||||
phoneNumber: string,
|
||||
options: {
|
||||
|
||||
Reference in New Issue
Block a user