Comments (3)
I've also been thinking about this issue but have been wary of implementing a solution like guarding and returning nil
because of data consistency concerns. In my own project, when fetching paginated data from a backend and the total count changes, I prefer to throw away old data and create a new array because you no longer know the old indexes match the updated.
What are your thoughts? In what situations are you running into this problem?
from pagedarray.
I got this error when server response had count field different than before what can happen quite often I think, depending how much queried data set changes by processing for example requests of other clients.
So in this case I've tried to change count. And that error happened.
I haven't thought about your solution to make new PagedArray. It seems quite good choice.
Let's think about the case when server data set is changing relatively often, for example various clients are adding new records to set that is matching our query:
(a) if changes occur very often, we would have to discard PagedArray content at every page fetched to make this consistent with server data.
(b) if changes occur very often, it can happen that count is the same as before but N records were deleted and N records were added
(c) changes occur very often - but new data is appearing at the end of our paged list (because it's sorted by ID, or creation date etc)
So some thoughts:
(a) resetting full array degrades performance a bit, prefetching doesn't make sense probably too and prefetched page can reset our currently visible page, in case (c) resetting array may be not necessary at all
(b) we cannot detect change by looking at count
(c) I would prefer to change count only and grow PagedArray at the end - exactly the same as data in api endpoint does
I think overall drawback of page number pagination is that it can be inconsistent with server. It's not the same as cursor pagination or other solutions. I think that depending on above (a), (b), (c) cases developers may want different solutions specific to their needs.
My current fix returns nil. I am not sure what would I choose for final solution: to return nil, make count immutable or to allow growing.
from pagedarray.
I agree with you that cursor pagination is a better approach to use for when data changes rapidly and making sure the client is absolutely consistent with the server is crucial.
The drawback is that you cannot fetch something in the middle of a list when scrolling fast and thus have to fetch all pages leading up to the one the user is currently looking at.
Ultimately, this is a performance/UX vs data integrity tradeoff. Depending on your application, you favor the one over the other. PagedArray
is aimed at solving the case where data integrity isn't the absolute highest priority. Originally it was created for an app where content isn't user-driven and it's more important to get content fast than making sure users get exactly what's on the server. Although you can certainly mitigate some data integrity risks with the techniques above, it's not 100% fool proof without another way for the server to signal that data has changed.
from pagedarray.
Related Issues (18)
- Does PagedArray play well with SwiftlyJSON? HOT 3
- Real working example HOT 3
- Please add support for tvOS. HOT 1
- How to deal with unknown data count HOT 3
- In comparison to using Realm. What are some tradeoffs and benefits of using this paging system? HOT 1
- Migrate to Swift 2.3 and Swift 3 HOT 4
- Changes in the dataset HOT 1
- How do we deal with memory warning issues when memory runs out because of setting so many new elements into the array? HOT 1
- Connecting with the API responses HOT 1
- Multiple API calls HOT 2
- Example with Alamofire HOT 1
- Array representation: [nil] HOT 2
- Index out of bounds HOT 5
- No shared scheme to work with Carthage HOT 2
- pageArray.loadedElements - Array index out of range when the last page is not fully loaded with elements HOT 3
- Setting the PagedArray with an empty array hit the assert "Page index out of bounds" HOT 5
- Swift 2.0 Update? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pagedarray.