[ http://jira.codehaus.org/browse/DISPL-19?page=all ] fabrizio giustina closed DISPL-19: ----------------------------------
Resolution: Duplicate Fix Version: 1.1 see DISPL-122 and DISPL-129 > Pagination - use subList instead of iterating all records > --------------------------------------------------------- > > Key: DISPL-19 > URL: http://jira.codehaus.org/browse/DISPL-19 > Project: DisplayTag > Type: Improvement > Components: Paging/Sorting > Versions: 1.0 RC2 > Reporter: fabrizio giustina > Fix For: 1.1 > Attachments: LongListPagingDraftChanges.zip > > > ==== > imported from sf tracker > id 1023387 > submitted by Ian Barnett - ianbdev > http://sourceforge.net/tracker/index.php?func=detail&group_id=73068&atid=536613&aid=1023387 > > ==== > The code that obtains a subset of records from the List > object (which is the subject of the display table) > iterates through all the records in the list until it finds > the ones it requires. > This is no problem for small lists where the subset might > be page 2 as 21-40 for example as only 20 records are > skipped during iteration. > But when the lists are very large (for example 20,000 > records) and the page is a high numbered page (e.g. > page 9001, records 18001-18021) the iteration is very > expensive as it must iterate through and skip over > 18,000 records just to get to the first record. > We have a simple modified verision of SmartListHelp.java > (based on the 1.0rc-1 library) that does not iterate > through unwanted records but rather uses the List > interface's subList method to retrieve only the records > required. > Then it is up to the application developer to either > burden the list with all (for example 20,000) records or > implement a List class that provides a subList method > that intelligently retrieves only the records required from > the List's datasource (e.g. may only grab 20 records at > a time for the database). > This is a very lightweight solution to the calls for > improved long list pagination that has a low impact on > the Display Tag code base. > Below is the current code for paginated record retrieval: > /** > * Returns a subsection of the list that contains just > the elements that are supposed to be shown on the > given page. > * @param pageNumber page number > * @return List subsection of the list that contains > just the elements that are supposed to be shown on the > given > * page > */ > protected List getListForPage(int pageNumber) { > log.debug("getListForPage page=" + pageNumber); > List list = new ArrayList(this.pageSize + 1); > int firstIndex = getFirstIndexForPage(pageNumber); > int lastIndex = getLastIndexForPage(pageNumber); > Iterator iterator = this.fullList.iterator(); > int j = 0; > while (iterator.hasNext()) { > Object object = iterator.next(); > if (j > lastIndex) { > break; > } else if (j >= firstIndex) { > list.add(object); > } > j++; > } > return list; > } > The recommended fix is: > protected List getListForPage(int pageNumber) { > log.debug("getListForPage page=" + pageNumber); > int firstIndex = getFirstIndexForPage(pageNumber); > int lastIndex = getLastIndexForPage(pageNumber); > return fullList.subList(firstIndex, lastIndex+1); > } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ displaytag-devel mailing list displaytag-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/displaytag-devel