Lazy Data Binding Using Callbacks

I am using PaginatedGrid plugin but when I use dataProvider as lazy load on page edit, grid filling is very slow. I make the call to the backend and then go do the setDataProvider of the grid. Does anyone have any suggestions? <dataProviderSet = DataProvider.fromCallbacks(query → {
int offset = query.getOffset();

        int limit = query.getLimit();
        size = limit;
        int pageSize = offset / limit;
        page = pageSize;
        try {
            listExfRichiesta = cduServiceConsumer.getExfRichieste(pageSize, limit).getContent();
        } catch (ConsumerException e) {
            
            e.printStackTrace();
        }
        return listExfRichiesta.stream();
    }, query -> {
        int intValue;
        try {
            intValue = cduServiceConsumer.getExfRichieste(page, size).getTotalElements().intValue();
            return intValue;
        } catch (ConsumerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return 0;

    });>

See if you can time how long the two calls you make take:

  1. cduServiceConsumer.getExfRichieste(pageSize, limit)
  2. cduServiceConsumer.getExfRichieste(page, size).getTotalElements()

Maybe I should build my own pagination component without using https://vaadin.com/directory/component/grid-pagination? Each time the page is changed, the data provider creation is very slow.

the time is: 1) 4 sec e 2) 3.4 s

It sounds like the bigger issue you have is on the backend side of things.

You can use the setItems(query->{}) API to avoid having to do a count call to speed things up a bit Binding Items to Components | Data Binding | Vaadin Docs

But to make it performant, you will need to investigate why the backend query is taking that long

Like @secure-leopard said, but IIRC, the Grid Pagination add-on don’t support the version of lazy data binding without the count query. In Viritin add-on there is PagingGrid component, that can do without the count query. Nevertheless, that optimisation only makes it perform in about 4 secs instead of your current 8.

If you can’t affect the backend call speed, I’d suggest to simply cache the calls. Drop in Ehcache or similar. That will help a lot, especially if your users can share the cache.

Here is my work in progress blog post that might help if you want to try caching: Caching - a quick workaround for slow backend queries - Google Docs

There is also this alternative component that is designed in different way than Grid and is supporting paging, also with callbacks, and full support of data view API’s (i.e. count estimator etc. things can be used)