Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite Loop created in pager.php #23

Closed
beauwest opened this issue Dec 6, 2011 · 6 comments
Closed

Infinite Loop created in pager.php #23

beauwest opened this issue Dec 6, 2011 · 6 comments
Labels
V2 V2 Client

Comments

@beauwest
Copy link

beauwest commented Dec 6, 2011

I've run into a really weird issue, I spent some time working on it but was unable to track it down completely.

The basic issue is this: When you try to add a per_page parameter to the request, in my case, for invoices, and the per_page number is a squared number of the total number of records available, it creates an infinite loop inside of the Recurly_Pager->current() method.

Example: I have 6 invoices for a particular user. I create this request:

$this->invoices = Recurly_InvoiceList::getForAccount(self::$user->storage->id, array('per_page' => 3));

It creates an infinite loop.

If I set the page size to 4, or anything other than a number that can be squared to reach the total invoices, it works fine.

Here's the current code:

  public function current()
  {
    while ($this->_position >= sizeof($this->_objects)) {
      if (isset($this->_links['next'])) {
        $num_objects = sizeof($this->_objects);
        $this->_loadFrom($this->_links['next']);
        $this->_position -= $num_objects;
      }
    }

    return $this->_objects[$this->_position];
  }

The problem happens inside of the while() loop. If we add && sizeof($this->_objects) > 0 to the while(), it partially fixes the problem, however, it creates an extra valid() record that is blank, meaning if we use a foreach(), we'll have a blank record.

I've spent too much time trying to track it down already, if it becomes a big enough issue, I'll have to try to fix it, but hopefully y'all will figure it out before I do.

One thought, is that part of the problem might be that the API returns a rel="next"; link in the header, even if there is no next page. Should that happen? If there's not another page, shouldn't it just leave that out? I think that would simplify the issue considerably.

@blasthaus
Copy link

I would love to see this resolved so there is no 'next page' link if there IS NO next page. it was driving me crazy as well as i was looping through all the next pages to get a full result set for accounts and subscriptions only to find out the last api call failed to return a result, so i had to add a condition for that.

@quicksketch
Copy link

I had this problem over in #31. I posted my code over there that attempted to pager results. Can anyone get a pager going that shows X number of results per page?

@blasthaus
Copy link

hey nate
let me know if you can Skype, i have a pager working
lots of other things that may be useful for you
-wil

On Fri, Jun 8, 2012 at 11:55 AM, Nathan Haug <
reply@reply.github.com

wrote:

I had this problem over in #31. I posted my code over there that attempted
to pager results. Can anyone get a pager going that shows X number of
results per page?


Reply to this email directly or view it on GitHub:

#23 (comment)

will@blasthaus.com
william linn

blasthaus
631 wisconsin str.
sf, ca 94107
www.blasthaus.com

@mbeale
Copy link

mbeale commented Dec 18, 2012

Paging is done automatically for you, there is no need to manually page through the results.

This code will scroll through all Active records

$subscriptions = Recurly_SubscriptionList::getActive();
foreach ($subscriptions as $subscription) {
print "Subscription: $subscription\n";
}

@quicksketch
Copy link

Paging is done automatically for you, there is no need to manually page through the results.

Yes I know it automatically retrieves additional results, what I needed was to say "show me the second page of 20 results, which start at result 21". I believe what I did 6 months ago is simply continue through the results until I got to the second page, then I started printing out the results. However as you might imagine this is incredibly inefficient; increasingly so as you get more pages.

@quicksketch
Copy link

My question on paging the list of results is still open at #31, unrelated to this issue.

@bhelx bhelx added the V2 V2 Client label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V2 V2 Client
Projects
None yet
Development

No branches or pull requests

6 participants