Skip to content

Commit 5448993

Browse files
committed
autocomplete [nfc]: Support caching normalized user names in AutocompleteDataCache
1 parent cc715e6 commit 5448993

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/model/autocomplete.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,21 @@ class MentionAutocompleteQuery {
426426
}
427427

428428
class AutocompleteDataCache {
429+
final Map<int, String> _normalizedNamesByUser = {};
430+
431+
/// The lowercase `fullName` of [user].
432+
String normalizedNameForUser(User user) {
433+
return _normalizedNamesByUser[user.userId] ??= user.fullName.toLowerCase();
434+
}
435+
429436
final Map<int, List<String>> _nameWordsByUser = {};
430437

431438
List<String> nameWordsForUser(User user) {
432-
return _nameWordsByUser[user.userId] ??= user.fullName.toLowerCase().split(' ');
439+
return _nameWordsByUser[user.userId] ??= normalizedNameForUser(user).split(' ');
433440
}
434441

435442
void invalidateUser(int userId) {
443+
_normalizedNamesByUser.remove(userId);
436444
_nameWordsByUser.remove(userId);
437445
}
438446
}

0 commit comments

Comments
 (0)