File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,11 @@ class MentionAutocompleteQuery {
88
99 final List <String > _lowercaseWords;
1010
11- bool testUser (User user) {
11+ bool testUser (User user, AutocompleteDataCache cache ) {
1212 // TODO test email too, not just name
1313 // TODO test with diacritics stripped, where appropriate
1414
15- // TODO cache, elsewhere
16- final List <String > nameWords = user.fullName.toLowerCase ().split (' ' );
15+ final List <String > nameWords = cache.nameWordsForUser (user);
1716
1817 int nameWordsIndex = 0 ;
1918 int queryWordsIndex = 0 ;
@@ -40,3 +39,15 @@ class MentionAutocompleteQuery {
4039 @override
4140 int get hashCode => Object .hash ('MentionAutocompleteQuery' , raw);
4241}
42+
43+ class AutocompleteDataCache {
44+ final Map <int , List <String >> _nameWordsByUser = {};
45+
46+ List <String > nameWordsForUser (User user) {
47+ return _nameWordsByUser[user.userId] ?? = user.fullName.toLowerCase ().split (' ' );
48+ }
49+
50+ void invalidateUser (int userId) {
51+ _nameWordsByUser.remove (userId);
52+ }
53+ }
Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ import '../example_data.dart' as eg;
88void main () {
99 test ('MentionAutocompleteQuery.testUser' , () {
1010 doCheck (String rawQuery, User user, bool expected) {
11- final result = MentionAutocompleteQuery (rawQuery).testUser (user);
11+ final result = MentionAutocompleteQuery (rawQuery)
12+ .testUser (user, AutocompleteDataCache ());
1213 expected ? check (result).isTrue () : check (result).isFalse ();
1314 }
1415
You can’t perform that action at this time.
0 commit comments