You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Need to implement pagination as handling hundreds of ParseObjects is a bit unwieldy. There's a couple of ways this can be done. One way could be to just get the whole result set, slice it and pass it to the paginate method with the current page and per page, though I personally think because of how Parse works that is against one the main aims of pagination i.e. selecting a specific chunk from the DB.
An alternative would be to just leave the all() method alone and have paginate return paginated results? I say this because I do think having an unpaginated all() method is still quite useful.
A sample solution could be to do something like:
public function paginate($results, $currentPage = 1, $perPage = 10, $keysToInclude = [])
{
$this->query->count(); // This is for length aware paginator.
$this->query->limit($perPage);
for ($i = 0; $i < count($keyToInclude); $i++) {
$this->query->includeKey($keyToInclude[$i]);
}
$this->query->skip((1-$currentPage) * $perPage);
$results = $this->query->find($this->useMasterKey);
return $this->paginator->make($results, $currentPage, $perPage)
}
As per Issue #30 we'd need to do the count up front. @hipsterjazzbo any thoughts/suggestions on how you originally envisaged this working? I haven't ran or tested the above code at all, just a thought whilst on my lunch break!
The text was updated successfully, but these errors were encountered:
Need to implement pagination as handling hundreds of ParseObjects is a bit unwieldy. There's a couple of ways this can be done. One way could be to just get the whole result set, slice it and pass it to the paginate method with the current page and per page, though I personally think because of how Parse works that is against one the main aims of pagination i.e. selecting a specific chunk from the DB.
An alternative would be to just leave the all() method alone and have paginate return paginated results? I say this because I do think having an unpaginated all() method is still quite useful.
A sample solution could be to do something like:
As per Issue #30 we'd need to do the count up front. @hipsterjazzbo any thoughts/suggestions on how you originally envisaged this working? I haven't ran or tested the above code at all, just a thought whilst on my lunch break!
The text was updated successfully, but these errors were encountered: