git ssb

10+

Matt McKegg / patchwork



Commit 0975af1e429bd7b240f035de3051d6ea2cf38c75

fix perf issues with auto-complete/suggest since using locale compare

fixes #770
Matt McKegg committed on 4/14/2018, 11:43:11 AM
Parent: 680a431c743ee01f79ddd270be7444e06f4c8cef

Files changed

modules/channel/obs/suggest.jschanged
modules/profile/async/suggest.jschanged
plugs/intl/sync/i18n.jschanged
modules/channel/obs/suggest.jsView
@@ -4,16 +4,18 @@
44 exports.needs = nest({
55 'channel.obs.recent': 'first',
66 'channel.obs.subscribed': 'first',
77 'channel.obs.mostActive': 'first',
8+ 'intl.sync.startsWith': 'first',
89 'keys.sync.id': 'first'
910 })
1011
1112 exports.gives = nest('channel.async.suggest')
1213
1314 exports.create = function (api) {
1415 var suggestions = null
1516 var subscribed = null
17+ var matches = api.intl.sync.startsWith
1618
1719 return nest('channel.async.suggest', function () {
1820 loadSuggestions()
1921 return function (word) {
@@ -31,9 +33,9 @@
3133 if (!suggestions) {
3234 var id = api.keys.sync.id()
3335 subscribed = api.channel.obs.subscribed(id)
3436 var mostActive = api.channel.obs.mostActive()
35- var contacts = computed([subscribed, mostActive], function (a, b) {
37+ var channels = computed([subscribed, mostActive], function (a, b) {
3638 var result = Array.from(a)
3739 b.forEach((item, i) => {
3840 if (!result.includes(item[0])) {
3941 result.push(item)
@@ -41,9 +43,9 @@
4143 })
4244 return result
4345 })
4446
45- suggestions = map(contacts, suggestion, {idle: true})
47+ suggestions = map(channels, suggestion, {idle: true})
4648 watch(suggestions)
4749 }
4850 }
4951
@@ -72,8 +74,4 @@
7274 } else {
7375 return fallback || ''
7476 }
7577 }
76-
77-function matches (text, startsWith) {
78- return text.slice(0, startsWith.length).localeCompare(startsWith, 'default', {sensitivity: 'base'}) === 0
79-}
modules/profile/async/suggest.jsView
@@ -5,8 +5,9 @@
55 'profile.obs.recentlyUpdated': 'first',
66 'contact.obs.following': 'first',
77 'about.obs.name': 'first',
88 'about.obs.imageUrl': 'first',
9+ 'intl.sync.startsWith': 'first',
910 'keys.sync.id': 'first'
1011 })
1112
1213 exports.gives = nest('profile.async.suggest')
@@ -14,8 +15,9 @@
1415 exports.create = function (api) {
1516 var suggestions = null
1617 var recentSuggestions = null
1718 var following = null
19+ var matches = api.intl.sync.startsWith
1820
1921 return nest('profile.async.suggest', function () {
2022 loadSuggestions()
2123 return function (word, defaultItems) {
@@ -97,8 +99,4 @@
9799 if (following.includes(id)) {
98100 return 'following'
99101 }
100102 }
101-
102-function matches (text, startsWith) {
103- return text.slice(0, startsWith.length).localeCompare(startsWith, 'default', {sensitivity: 'base'}) === 0
104-}
plugs/intl/sync/i18n.jsView
@@ -9,9 +9,10 @@
99 'locales',
1010 'localeNames',
1111 'i18n',
1212 'i18n_n',
13- 'time'
13+ 'time',
14+ 'startsWith'
1415 ])
1516
1617 exports.needs = nest({
1718 'intl.sync.locale': 'first',
@@ -22,17 +23,25 @@
2223
2324 exports.create = (api) => {
2425 let _locale
2526
27+ // TODO: this should probably follow the selected language
28+ var collator = new Intl.Collator('default', {sensitivity: 'base', usage: 'search'})
29+
2630 return nest('intl.sync', {
2731 locale,
2832 locales,
33+ startsWith,
2934 localeNames,
3035 i18n,
3136 i18n_n: i18nN,
3237 time
3338 })
3439
40+ function startsWith (text, startsWith) {
41+ return collator.compare(text.slice(0, startsWith.length), startsWith) === 0
42+ }
43+
3544 // Get locale value in setting
3645 function locale () {
3746 return api.settings.obs.get('patchwork.lang')
3847 }

Built with git-ssb-web