File tree 2 files changed +16
-4
lines changed
2 files changed +16
-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,15 @@ 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
+
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;
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