-
-
Notifications
You must be signed in to change notification settings - Fork 585
XWIKI-22540: Slow loading time when changing the icons theme to Silk in the Icon picker #3537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 8 commits
96d740e
2392ffa
fd1505e
b50e558
cdc937f
0053841
53b88e0
3642613
1546dc7
ec97807
4622902
127d585
6663d3c
a0087f8
8a7c415
4b1f7e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -46,15 +46,15 @@ | |||||||||
#set ($discard = $map.put('currentIconTheme', $services.icon.currentIconSetName)) | ||||||||||
#jsonResponse($map) | ||||||||||
########################### | ||||||||||
## DATA: ICON_AMOUNT | ||||||||||
## DATA: ICON COUNT | ||||||||||
########################### | ||||||||||
#elseif ($request.action == 'data_iconamount') | ||||||||||
#elseif ($request.action == 'data_icon_count') | ||||||||||
#set ($iconTheme = $request.iconTheme) | ||||||||||
#set ($xwikiIcons = $collectiontool.sort($services.icon.getIconNames($iconTheme))) | ||||||||||
#set ($iconNamePrefix = $request.query.toLowerCase()) | ||||||||||
#set ($total = 0) | ||||||||||
#foreach ($xwikiIcon in $xwikiIcons) | ||||||||||
#if ("$!iconNamePrefix" == '' || $xwikiIcon.startsWith($iconNamePrefix)) | ||||||||||
#if ("$!iconNamePrefix" == '' || $stringtool.startsWithIgnoreCase($xwikiIcon, $iconNamePrefix)) | ||||||||||
#set ($total = $total + 1) | ||||||||||
#end | ||||||||||
#end | ||||||||||
|
@@ -68,21 +68,27 @@ | |||||||||
#set ($xwikiIcons = $collectiontool.sort($services.icon.getIconNames($iconTheme))) | ||||||||||
#set ($iconNamePrefix = $request.query.toLowerCase()) | ||||||||||
#set ($offset = $numbertool.toNumber($request.offset).intValue()) | ||||||||||
#set ($number = $numbertool.toNumber($request.number).intValue()) | ||||||||||
#if (!$offset || $offset < 0) | ||||||||||
#set($offset = 0) | ||||||||||
#set ($limit = $numbertool.toNumber($request.limit).intValue()) | ||||||||||
#if (!$offset || $offset < 0) | ||||||||||
#set ($offset = 0) | ||||||||||
#end | ||||||||||
#foreach ($xwikiIcon in $xwikiIcons) | ||||||||||
#if ("$!iconNamePrefix" == '' || $xwikiIcon.startsWith($iconNamePrefix)) | ||||||||||
#if (($foreach.count >= $offset) && (!$number || $foreach.count < $offset + $number)) | ||||||||||
#if ("$!iconNamePrefix" == '' || $stringtool.startsWithIgnoreCase($xwikiIcon, $iconNamePrefix)) | ||||||||||
## We compare $foreach.count - 1 to our values since foreach.count is 1 based index (!= standard 0 based index) | ||||||||||
## We want to make sure we retrieve only the right values. | ||||||||||
#if (($foreach.count - 1 >= $offset) && (!$limit || $foreach.count - 1 < $offset + $limit)) | ||||||||||
#set ($icon = { | ||||||||||
'name': $xwikiIcon, | ||||||||||
'render': $services.icon.renderHTML($xwikiIcon, $iconTheme) | ||||||||||
'render': $services.icon.renderHTML($xwikiIcon, $iconTheme), | ||||||||||
'queryString': $iconNamePrefix | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this used client-side? |
||||||||||
}) | ||||||||||
#if ($request.metadata == 'true') | ||||||||||
#set ($icon.metadata = $services.icon.getMetaData($xwikiIcon, $iconTheme)) | ||||||||||
#end | ||||||||||
#set ($discard = $icons.add($icon)) | ||||||||||
#elseif($limit && ($foreach.count - 1 >= $offset + $limit)) | ||||||||||
## We already got all the icons we wanted, we can exit the foreach loop. | ||||||||||
#break | ||||||||||
#end | ||||||||||
#end | ||||||||||
#end | ||||||||||
|
@@ -259,12 +265,13 @@ require(['jquery', 'xwiki-icon-picker'], function($) { | |||||||||
*/ | ||||||||||
var displayList = function(iconList) { | ||||||||||
// Filter the icons we display based on the value of the input field. | ||||||||||
let selectedIconName = ''; | ||||||||||
let selectedIconName = currentInput[0].value; | ||||||||||
if (currentInput.data('xwikiIconPickerSettings') !== '') { | ||||||||||
// We need to remove the prefix for comparison to UI elements. | ||||||||||
selectedIconName = currentInput[0].value.replace(currentInput.data('xwikiIconPickerSettings').prefix, ''); | ||||||||||
} | ||||||||||
// For each icon | ||||||||||
iconList.forEach(icon => { | ||||||||||
iconList.forEach(icon => { | ||||||||||
// Display the icon | ||||||||||
if (selectedIconName === '' || icon.name.includes(selectedIconName)) { | ||||||||||
var displayer = $(document.createElement('div')); | ||||||||||
|
@@ -286,29 +293,45 @@ require(['jquery', 'xwiki-icon-picker'], function($) { | |||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Load the icon list (get the JSON from the server) and display it afterwards | ||||||||||
* Load part of the icon list (get the JSON from the server) and display it afterwards | ||||||||||
*/ | ||||||||||
var loadIconList = function(iconTheme) { | ||||||||||
let pageSize = 20; | ||||||||||
let maxItems = 0; | ||||||||||
$.getJSON(getResourceURL('data_iconamount', 'iconTheme=' + iconTheme) , function(dataIconAmount) {maxItems = | ||||||||||
dataIconAmount}); | ||||||||||
$.getJSON(getResourceURL('data_icons', 'iconTheme=' + iconTheme + '&number=' + pageSize.toString()), | ||||||||||
function(dataIcons) { | ||||||||||
// Put the result in the icons map | ||||||||||
icons[iconTheme] = dataIcons; | ||||||||||
// Display the list | ||||||||||
displayList(icons[iconTheme]); | ||||||||||
// Hide the spinner | ||||||||||
spinner.hide(); | ||||||||||
}); | ||||||||||
// Load more items if the user scrolled at the end of the current list and everything is not loaded yet. | ||||||||||
iconListSection.off('scroll'); | ||||||||||
iconListSection.on('scroll', event => { | ||||||||||
if ( iconListSection[0].scrollTop + iconListSection[0].clientHeight >= iconListSection[0].scrollHeight) { | ||||||||||
console.log('I am on the bottom!'); | ||||||||||
var pageSize = 20; | ||||||||||
var maxItems = -1; | ||||||||||
Comment on lines
+299
to
+300
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
// Recursive function helper. This calls the page to retrieve the icon information, by chunk of pageSize. | ||||||||||
// After receiving the icon info, it displays them and calls itself again if the colortheme is not fully loaded. | ||||||||||
var partialLoadIcon = function () { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
let itemCount = icons[iconTheme].length; | ||||||||||
if( maxItems === -1) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
// The first call will retrieve the total count of items we'll need to get. | ||||||||||
$.getJSON(getResourceURL('data_icon_count', 'iconTheme=' + iconTheme) , function(dataIconCount) { | ||||||||||
maxItems = dataIconCount | ||||||||||
}); | ||||||||||
} | ||||||||||
}); | ||||||||||
$.getJSON(getResourceURL('data_icons', 'iconTheme=' + iconTheme | ||||||||||
+ '&offset=' + itemCount.toString() | ||||||||||
+ '&limit=' + pageSize.toString()), | ||||||||||
function(dataIcons) { | ||||||||||
// Put the result in the icons map | ||||||||||
icons[iconTheme].push.apply(icons[iconTheme], dataIcons); | ||||||||||
// Display the list of new icons. | ||||||||||
// Since this recursive calls can take a while on poor network, we want to make sure we only display the newly | ||||||||||
// retrieved icons if the iconTheme input still has their value. | ||||||||||
if (iconTheme === currentIconTheme) { | ||||||||||
displayList(dataIcons); | ||||||||||
} | ||||||||||
// Whatever the value of the current icon theme, we finish loading this one so that we have a correct state | ||||||||||
// if the user ever comes back to it. | ||||||||||
if (itemCount + pageSize < maxItems) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no guarantee that |
||||||||||
partialLoadIcon(maxItems); | ||||||||||
} else if (iconTheme === currentIconTheme) { | ||||||||||
// All icons have been loaded and the user didn't change the icon theme in the meantime. | ||||||||||
// We can finalize the rendering and hide the spinner. | ||||||||||
spinner.hide(); | ||||||||||
} | ||||||||||
}); | ||||||||||
}; | ||||||||||
partialLoadIcon(); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
|
@@ -356,6 +379,8 @@ require(['jquery', 'xwiki-icon-picker'], function($) { | |||||||||
currentIconTheme = iconThemeSelector.val(); | ||||||||||
// Remove all the displayed icons | ||||||||||
$('.xwikiIconPickerIcon').remove(); | ||||||||||
// And reset the state of the loading spinner. | ||||||||||
spinner.hide(); | ||||||||||
// Display the new ones | ||||||||||
if (icons[currentIconTheme].length == 0) { | ||||||||||
// if the icon theme has not already been loaded, load it | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$foreach.index
is also available, and it's 0-based, see https://github.com/search?q=repo%3Axwiki%2Fxwiki-platform+%22foreach.index%22+language%3AXML&type=code&l=XML .