framework icon indicating copy to clipboard operation
framework copied to clipboard

DataProvider API should not require developer to report the size fo the data

Open mstahv opened this issue 8 years ago • 22 comments
trafficstars

Version 8.0.0.beta2

The DataProvider API is designed in such a way that it is very hard to provide scalable implementation for large data set. Getting the number of objects in the "query" often requires database to scroll through the whole result set which causes really slow queries. If non filtered use cases developers could often optimize it a bit (Grid), but in e.g. ComboBox there is no efficient way for developer to do it.

The lazy loading should not required developer to provide the size. The UI should just keep getting the next page until result set is smaller than requested. In real life users never scroll so long that this would become slow, instead they'll add more detailed search term.

mstahv avatar Feb 07 '17 21:02 mstahv

The API has explicitly been designed to allow introducing this feature, but those plans have not been realized since there hasn't been enough time to make any component implementation work accordingly.

For Grid, there are some edge cases where the internal bookkeeping of the component falls apart if it needs to adjust the scales of the scrollbars while data is being fetched.

For ComboBox, this would at the very least require changes to how the paging info is displayed (e.g. "1-10/246" that is currently displayed). There might also be some bookkeeping issues similar to the ones already encountered with Grid.

Legioth avatar Feb 08 '17 07:02 Legioth

This would make LazyLoading much more powerfull and save developers a lot of work...

neerup avatar Mar 08 '17 11:03 neerup

And this could also be solution/workaround for #6290 -- assuming that users never scroll 200 000+ rows "just for fun" scrollbar can re-adjust until browser ceases to work. Thats far better than the current behaviour that renders grid uselesse if there are theoretically more than 200k records available but user only looks at the top 100 records

StefanPenndorf avatar Mar 21 '17 15:03 StefanPenndorf

Not having this feature is really becoming a problem for us.. We have tried to hack a solution where we return a fictive row count and refresh with a larger row count when the user scrolls near the end. But the result is not pretty because of the many refreshes. Please make this a priority.

neerup avatar Jun 12 '17 05:06 neerup

One more possibly related issue from different angle - #10104.

drewoko avatar Sep 28 '17 07:09 drewoko

Any chance this will be part of Vaadin 10?

neerup avatar Jan 30 '18 15:01 neerup

@neerup , better to ask at https://gitter.im/vaadin/flow

elmot avatar Apr 03 '18 17:04 elmot

Out of curiosity on this specific ticket, I made a quick PoC changing parts of the DataCommunicator to not deal with the row count but just keep on fetching until you hit a wall, it seems to work more or less out of the box. There's at least some problems when it comes to the Grid component and scrolling which makes it a bit unresponsive at times. I did not test it yet with ComboBox.

tsuoanttila avatar May 16 '18 08:05 tsuoanttila

Please make this part of the Framework so we don't have to hack the rowcount callback

neerup avatar May 16 '18 09:05 neerup

Awesome @tsuoanttila, this is truly valuable features. Hopefully you can share a prototype soon for early testing.

mstahv avatar May 16 '18 10:05 mstahv

@tsuoanttila Waiting for that too.

ilgun avatar Jul 03 '18 14:07 ilgun

As I currently am a bit busy, I am not able to make it into a proper add-on in the near future. You can check out the beef of the add-on from this gist https://gist.github.com/tsuoanttila/370dfbadcb27346db42a03de15f85fb9

You can use it with for example Grid with

public class SizelessGrid<T> extends Grid<T> {
    public SizelessGrid() {
        super(new SizelessDataCommunicator<>());
    }
}

tsuoanttila avatar Jul 05 '18 09:07 tsuoanttila

Stole your innovation right away 😜 and did some tests:

https://github.com/viritin/viritin/commit/7ac0e05c733b6612cec7b9b330a9198ed326ecf9

Once I somehow got some empty rows to the end of the Grid, but it still didn't break and seems to work otherwise just fine. If you think the example and the SizelessGrid looks good I'm ready to cut a release.

mstahv avatar Jul 05 '18 10:07 mstahv

Hi @TatuLund thanks for the example. Unfortunately, this does not fully fix the problem. As @mstahv noted, the grid has empty rows at the bottom any time the size of the returned list of elements is < the fetch limit. Setting the min push rows to a high number will fetch the first page but scrolling resets the push rows range and fetches some of the same rows over again. I'm afraid this isn't a viable workaround.

markathomas avatar Oct 03 '18 11:10 markathomas

I have a similar issue as described: https://vaadin.com/forum/thread/17554172

I tried @tsuoanttila SizelessDataCommunicator but it did not solve the problem. That workaround loads the first page, then calls fetch() many times loading small chunks of data until it's read everything even though the Grid has not been scrolled. The scrollbar is also never displayed. It's slightly better in the sense that the page does eventually load and not hang, but without the scrollbar being displayed it's still very broken.

mcooper7290 avatar Mar 11 '19 18:03 mcooper7290

I was trying to make the prototype by @tsuoanttila work, but couldn't make it anymore. Throws an exception on the client side. I guess it worked with some certain Vaadin version only 😥

Has somebody a working setup with it?

mstahv avatar Aug 14 '19 13:08 mstahv

Looks like it was a regression, now reverted. Anyways, if somebody has used it in production environment, I'd love to hear your experiences. Hoping to make this an official feature at some point.

mstahv avatar Aug 14 '19 15:08 mstahv

I spent a while to finetune the solution. The component is now called LazyGrid in Viritin 2.11 and it also matches backend queries to "pages" (configurable size), to make it much easier to connect certain backend, such as those based on Spring Data.

Resources:

mstahv avatar Aug 15 '19 20:08 mstahv

Wrote some of my ideas of the topic to a blog article: https://vaadin.com/blog/request-for-comments-lazy-data-binding-improvements

mstahv avatar Aug 22 '19 08:08 mstahv

Is there a way to support this with Vaadin14?

vilmosnagy avatar May 05 '20 17:05 vilmosnagy

Not yet, but the team is currently working on making this a standard feature. I hope we have something to test in pre-releases in couple of weeks.

mstahv avatar May 05 '20 18:05 mstahv

Hey @mshabarov & @rolfsmeds, Isn't this thing done 🤔 I guess not completely as TreeGrid is still there to tackle? Maybe create a more specific one for it?

mstahv avatar Jan 11 '23 15:01 mstahv