Datasources requesting twice to server #420

rvalle opened this Issue May 10, 2011 · 7 comments

4 participants


don't know if it is a bug or just an API change, but since 1.5.0 I am seen my server always hit twice for each query.

It is also happening on 1.6.0.beta.2

Anybody also experiencing it?


It seems that SparseArrays work different now.

we used to provide length and results in one go, but now as length is provided the DataSource is hit straight away.


It is still happening in 1.6.0.rc.2


It seems that the sparse array / progressive load pattern has changed.
may be now there is another way to provide arrayLength and first set of results at the same time.


Is this a duplicate of #474 or something different?


No, this is a different thing.

Basically, if you implement incremental loading as described in SC wiki, you get double requests.

The proposed implementation is:
1. sparseArray calls delegate sparseArrayDidRequestLength
2. instead of fetching just the array length, call delegate's sparseArrayDidRequestRange and provide first window of results and length with just one server request.
3. in the callback:
3.a set the array length
3.b push the results into the array

That worked fine in the previous implementation of SC, with 1.6.0 the problem is that as soon as you provide the length (3.a), within the same run loop, the sparse array will trigger another request to the server for the first window of results before 3.b is executed. So you end up having two requests to the server. This happens even if you use a beginPropertyChanges and endPropertyChanges for 3.a and 3.b.

In my opinion, when the sparseArrayDidRequestLength happens there should be a method to provide the length and another to provide the length and the first window of result as a single operation.

It does make sense to provide both length and first window of results in one go, but the API as it is now does not support explicitly this usage.


Hi @rvalle, I have the same problem, I looked the sparseArray code and I think that we have a temporal trick that prevent to call twice, and you don't need to touch the SC.SparseArray. here is the code that we need to add in the callback before calling provideObjectsInRange(...):

if (sparseArray._length === undefined) {

This code resolves two problems: Call provideLength one time and tell provideLength that is in "requestingLength" mode. to prevent call the arrayContentDidChange.

For the other hand, back to the SC.SparseArray, I think that the problem is in the length property, because when call the sparseArrayDidRequestLength delegate method, is expected to set with provideLength() before calling this._requestingLength--; and this doesn't happens, because we will call sparseArrayDidRequestRange.

I think that the solution is to add a callback to the sparseArrayDidRequestLength to provide the length when ready in a asynchronous way.

For now this trick works for me, hope this help.

SproutCore member

Please reopen if this is still an issue. But I recently added a demo of working with the SparseArray here and didn't have any problems:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment