Infinite scrolling/data paging and out-of-sync page results -
i'm develop infinite scrolling of items (which specific ux of paged items) in web app, i'm bit confused how approach problem of new items being added while 1 user scrolls/pages through items. how deal such unsynced data?
suppose when open page database has 100 items.
- user 1 navigates page request first 10 items , displays them
- user 1 starts scrolling , gets point when page requests next 10 items
- user 2 adds new item database has 101 items
- user 1 scrolls requesting next 10 items.
what should happen on backend?
- if user scrolled down request 10 items last id on ok
- if user scrolled request previous 10 items there's 1 @ top now?
how solved? maybe on stackexchange sites content being paged , stream cache changes while user navigates pages of questions?
should question asked on programmers maybe? i'm not sure...
this solved not doing paging traditionally providing
- page index and
- page size,
but rather providing
- last displayed record id and
- page size
this referred keyset paging or key seek method paging. both require additional parameters ordering , filtering, that's similar both techniques it's irrelevant answer.
this prevents invalid pages being returned when new items being added top of list, has downside not give ability jump pages (i.e. page 10, while we're looking @ page 5). that's why used in specific scenarios infinite scrolling problem isn't present or desired.
see performance comparison , lots of explanation regarding key seek method:
http://use-the-index-luke.com/sql/partial-results/fetch-next-page
so want along these lines (suppose we're ordering chronologically in reverse order , assuming createdate such high precision it's considered unique):
with lastrecord ( select createddate records id = @lastrecordid ) select r.* records r, lastrecord l r.createddate < l.createddate offset 0 rows fetch first @pagesize rows only;
Comments
Post a Comment