Forum BigDB Detecting end of range when loading range.

Discussion and help relating to the PlayerIO database solution, BigDB.

Detecting end of range when loading range.

Postby robertflesch » September 19th, 2017, 4:27 pm

I am loading a range of objects from a table.
Is there any way to know when you have reached the last object?

Managed to find a possible work around, but it would be very handy to know when you have received the last record, or you could send another message which is "end of range".
robertflesch
Paid Member
 
Posts: 136
Joined: April 22nd, 2013, 9:18 pm

Re: Detecting end of range when loading range.

Postby Henrik » September 23rd, 2017, 8:22 am

If you receive fewer objects than your limit, you have reached the last object.

Sort of edge case: All the objects in your range fit into X whole pages, in which case you'll need to make one more loadrange call, which will contain only one element, that which was the last element of the previous page that you would have used as the start parameter.

Imagine your index contains objects {a, b, c, d, e, f}:

loadrange(..., null, null, null, 3) returns {a, b, c}.
loadrange(..., null, c, null, 3) returns {c, d, e}.
loadrange(..., null, e, null, 3) returns {e, f}. 2 < 3, so you're at the end.

Imagine the index contains one more object, g:

loadrange(..., null, e, null, 3) now returns {e, f, g}. 3=3, so there might be more objects.
loadrange(..., null, g, null, 3) returns {g}. 1 < 3, so you're at the end.
Henrik
.IO
 
Posts: 1832
Joined: January 4th, 2010, 1:53 pm

Re: Detecting end of range when loading range.

Postby robertflesch » October 27th, 2017, 2:42 pm

I this sort of works, but how long do I need to wait until I know it has returned everything?
See how this is kind of open ended?
A simple "end of set" message would make things deterministic.
robertflesch
Paid Member
 
Posts: 136
Joined: April 22nd, 2013, 9:18 pm

Re: Detecting end of range when loading range.

Postby Henrik » October 28th, 2017, 5:09 am

Huh? There's no substantial difference between loading until you get less than page size objects, and having some sort of extra flag on the resultset saying you're at the end. You would normally require the same amount of calls to loadrange to fetch all objects.
Henrik
.IO
 
Posts: 1832
Joined: January 4th, 2010, 1:53 pm

Re: Detecting end of range when loading range.

Postby robertflesch » October 29th, 2017, 11:23 pm

Ok, I see, if the returned set is less than the set limit, you are at the end of the range.
So how about if the last returned set is the same size as the set limit. Will you get another set of size 0?
robertflesch
Paid Member
 
Posts: 136
Joined: April 22nd, 2013, 9:18 pm

Re: Detecting end of range when loading range.

Postby Henrik » October 30th, 2017, 9:18 am

No, you'll get an extra set with a single object in it, but you'll only incur this extra load if the objects in the index exactly fit X pages, but if you have a large enough page size, the probability of this becomes very low, so effectively you'll only need to do the minimum number of loadrange calls anyway to get the entire table.
Henrik
.IO
 
Posts: 1832
Joined: January 4th, 2010, 1:53 pm

Re: Detecting end of range when loading range.

Postby robertflesch » October 30th, 2017, 2:27 pm

What will the single object in this extra set be? Is that extra set with a single object in it a repeat of an existing object? I don't think this edge case is covered in the documentation (but I may be wrong).

So lets say I have 100,000 users, and the average user has 75 records in a table (+-50 records). The default range size is 100. From that I would estimate that 50 users would have exactly 100 records. So 50+ times a day I would hit this case.

As a developer I have to design for the edge cases if I want reliable software.
robertflesch
Paid Member
 
Posts: 136
Joined: April 22nd, 2013, 9:18 pm

Re: Detecting end of range when loading range.

Postby Henrik » October 30th, 2017, 7:19 pm

Just check my example above. It will contain the last object in the index.

LoadRange always returns objects inclusively, and since you use the last object of each set as the starting point for the next, all sets will be overlapping. So it's not the case that you have to give only the last set some special treatment, you have to skip the first object of every set except the first set returned. (Because in that case you use null as the start object)
Henrik
.IO
 
Posts: 1832
Joined: January 4th, 2010, 1:53 pm

Re: Detecting end of range when loading range.

Postby robertflesch » October 31st, 2017, 2:57 pm

I see now, since I use the last object in the previous set as the first object in the next set. When a set comes back with no additional objects, I am done.
robertflesch
Paid Member
 
Posts: 136
Joined: April 22nd, 2013, 9:18 pm


Return to BigDB



cron