cache icon count to make filtering more responsive on slower connections, #4044

This commit is contained in:
zadam 2023-06-20 21:31:25 +02:00
parent 6cfd18b29b
commit 8095c77b91

View File

@ -141,7 +141,8 @@ export default class NoteIconWidget extends NoteContextAwareWidget {
} }
async renderDropdown() { async renderDropdown() {
const iconToCountPromise = this.getIconToCountMap(); const iconToCount = await this.getIconToCountMap();
const {icons} = (await import('./icon_list.js')).default;
this.$iconList.empty(); this.$iconList.empty();
@ -157,9 +158,6 @@ export default class NoteIconWidget extends NoteContextAwareWidget {
); );
} }
const {icons} = (await import('./icon_list.js')).default;
const iconToCount = await iconToCountPromise;
const categoryId = parseInt(this.$iconCategory.find('option:selected').val()); const categoryId = parseInt(this.$iconCategory.find('option:selected').val());
const search = this.$iconSearch.val().trim().toLowerCase(); const search = this.$iconSearch.val().trim().toLowerCase();
@ -192,9 +190,12 @@ export default class NoteIconWidget extends NoteContextAwareWidget {
} }
async getIconToCountMap() { async getIconToCountMap() {
const {iconClassToCountMap} = await server.get('other/icon-usage'); if (!this.iconToCountCache) {
this.iconToCountCache = server.get('other/icon-usage');
setTimeout(() => this.iconToCountCache = null, 20000); // invalidate cache after 20 seconds
}
return iconClassToCountMap; return (await this.iconToCountCache).iconClassToCountMap;
} }
renderIcon(icon) { renderIcon(icon) {