Skip to content

Commit 8ac0e16

Browse files
committed
autocomplete [nfc]: Support caching normalized user names in AutocompleteDataCache
1 parent c4744fb commit 8ac0e16

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
@@ -455,13 +455,21 @@ class MentionAutocompleteQuery {
455455
}
456456

457457
class AutocompleteDataCache {
458+
final Map<int, String> _normalizedNamesByUser = {};
459+
460+
/// The lowercase `fullName` of [user].
461+
String normalizedNameForUser(User user) {
462+
return _normalizedNamesByUser[user.userId] ??= user.fullName.toLowerCase();
463+
}
464+
458465
final Map<int, List<String>> _nameWordsByUser = {};
459466

460467
List<String> nameWordsForUser(User user) {
461-
return _nameWordsByUser[user.userId] ??= user.fullName.toLowerCase().split(' ');
468+
return _nameWordsByUser[user.userId] ??= normalizedNameForUser(user).split(' ');
462469
}
463470

464471
void invalidateUser(int userId) {
472+
_normalizedNamesByUser.remove(userId);
465473
_nameWordsByUser.remove(userId);
466474
}
467475
}

0 commit comments

Comments
 (0)