The following comment has been added to this issue:

     Author: Lim Eu Gene
    Created: Sun, 5 Dec 2004 10:55 PM
       Body:
Note that the patch above needs some work to add support for EL expressions.
---------------------------------------------------------------------
View this comment:
  http://jira.codehaus.org/browse/DISPL-19?page=comments#action_27525

---------------------------------------------------------------------
View the issue:
  http://jira.codehaus.org/browse/DISPL-19

Here is an overview of the issue:
---------------------------------------------------------------------
        Key: DISPL-19
    Summary: Pagination - use subList instead of iterating all records
       Type: Improvement

     Status: Unassigned
   Priority: Major

 Original Estimate: Unknown
 Time Spent: Unknown
  Remaining: Unknown

    Project: DisplayTag
 Components: 
             Paging/Sorting
   Versions:
             1.0 RC2

   Assignee: 
   Reporter: fabrizio giustina

    Created: Sat, 25 Sep 2004 5:17 AM
    Updated: Sun, 5 Dec 2004 10:55 PM

Description:
====
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);
}


---------------------------------------------------------------------
JIRA INFORMATION:
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

If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
displaytag-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/displaytag-devel

Reply via email to