The following comment has been added to this issue:

     Author: Lim Eu Gene
    Created: Sun, 5 Dec 2004 9:09 PM
       Body:
tableModel currently iterates through all the rows in the List, and 
SmartListHelper gets the full list from tableModel.

Here is a proposal patch that passes a subset of the rows to tableModel, but 
passes the complete list to SmartListHelper. The idea is to pass a lazyily 
initialized list to SmartListHelper. In this patch, two methods are modified in 
TableTag.java

- In the method initParameters(), here is the modified code:
        // can we actually skip any row?
        if (wishOptimizedIteration && ((sortColumn == -1 // and we are not 
sorting
            || !finalSortFull // or we are sorting with the "page" behaviour
            ) && (this.currentMediaType == MediaTypeEnum.HTML // and we are not 
exporting
            || !this.properties.getExportFullList()) // or we are exporting a 
single page
            ))
        {
            optimizedIteration = true;

            int start = 0;
            int end = 0;
            if (this.offset > 0)
            {
                start = this.offset;
            }
            if (length > 0)
            {
                end = start + this.length;
            }

            if (this.pagesize > 0)
            {
                start = (this.pageNumber - 1) * this.pagesize;
                end = start + this.pagesize;
            }

            // rowNumber starts from 1
            filteredRows = new LongRange(start + 1, end);
            if (this.list instanceof List) {
                List extendedList = (List) this.list;
                List subList = extendedList.subList(start, end - 1);
                this.tableIterator = subList.iterator();
            } else {
                this.tableIterator = IteratorUtils.getIterator(this.list);
            }
        }
        else
        {
            filteredRows = new LongRange(1, Long.MAX_VALUE);
            this.tableIterator = IteratorUtils.getIterator(this.list);
        }

- In the method setupViewableData(), here is the modified code:

        Object originalData = this.tableModel.getRowListFull();

        // If they have asked for a subset of the list via the length
        // attribute, then only fetch those items out of the master list.
        List fullList = CollectionUtil.getListFromObject(originalData, 
this.offset, this.length);
        List smartFullList = fullList;
        
        if (this.list instanceof List) {
            smartFullList = CollectionUtil.getListFromObject(this.list, 
this.offset, this.length); 
        }

        int pageOffset = this.offset;
        // If they have asked for just a page of the data, then use the
        // SmartListHelper to figure out what page they are after, etc...
        if (this.pagesize > 0)
        {
            this.listHelper = new SmartListHelper(smartFullList, 
smartFullList.size(), this.pagesize, this.properties);
            this.listHelper.setCurrentPage(this.pageNumber);
            pageOffset = this.listHelper.getFirstIndexForCurrentPage();
            smartFullList = this.listHelper.getListForCurrentPage();
        }

        this.tableModel.setRowListPage(fullList);
        this.tableModel.setPageOffset(pageOffset);
---------------------------------------------------------------------
View this comment:
  http://jira.codehaus.org/browse/DISPL-19?page=comments#action_27524

---------------------------------------------------------------------
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 9:09 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