Hi,

I noticed a possible inefficiency in AbstractPageableView's getItemModels() 
method:

/**
     * This method retrieves the subset of models for items in the current page 
and allows
     * RefreshingView to generate items.
     * 
     * @return iterator over models for items in the current page
     */
    @Override
    protected Iterator<IModel<T>> getItemModels()
    {
        long offset = getFirstItemOffset();
        long size = getViewSize();

        Iterator<IModel<T>> models = getItemModels(offset, size);

        models = new CappedIteratorAdapter<T>(models, size);

        return models;
    }

The getViewSize() method will issue a getRowCount() call which in DataViewBase 
will call the size() method of the DataProvider: 

public long getViewSize()
    {
        return Math.min(getItemsPerPage(), getRowCount() - 
getFirstItemOffset());
    }

As far as I can see, this happens so that the call to getItemModels(offset, 
size) would not ask for more items, than there is in the underlying provider. 

However, ListDataProvider defends against getting more items than present in 
the list:


@Override
    public Iterator<T> iterator(final long first, final long count)
    {
        List<T> list = getData();

        long toIndex = first + count;
        if (toIndex > list.size())
        {
            toIndex = list.size();
        }
        return list.subList((int)first, (int)toIndex).listIterator();
    }

Also databases can handle a LIMIT clause that asks for more rows than present 
in the dataset.

The reason I was looking at this code is a DataView element I'm using on the 
front page of a public web application that fetches and displays the N most 
recent entries from a comment table without any paging components added to the 
DataView and I was seeing a simple "SELECT count(id) FROM comment"-like query 
taking 9% of all sql time according to JavaMelody for the last few days. 

I've changed the implementation by overriding the getItemModels() method to 
call directly getItemsPerPage instead of getViewSize and it got rid of the 
count selects and everything else seems to be working fine.

I'm wondering if there is maybe some other reason why getItemModels() is 
calling getViewSize instead of getItemsPerPage that I've missed. If not should 
I create a ticket in jira? 

Thanks,

Janos

--
pilar.hu




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to