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:
parent
9376dba806
commit
6150c3dcc0
2 changed files with 18 additions and 8 deletions
|
@ -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: {
|
||||
|
|
Loading…
Add table
Reference in a new issue