Bugs item #1023387, was opened at 2004-09-07 11:40
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=536613&aid=1023387&group_id=73068
Category: main tag library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Ian Barnett (ianbdev)
Assigned to: Nobody/Anonymous (nobody)
Summary: Pagination - use subList instead of iterating all records
Initial Comment:
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);
}
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=536613&aid=1023387&group_id=73068
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click
_______________________________________________
displaytag-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/displaytag-devel