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