aweber / AWeber-API-Ruby-Library

DEPRECATED - Ruby interface to AWeber's API.
http://www.aweber.com
BSD 3-Clause "New" or "Revised" License
25 stars 18 forks source link

Calling `#subscribers` on `List` consistently hitting API Rate Limit #36

Open rmontgomery429 opened 8 years ago

rmontgomery429 commented 8 years ago

We are integrating with the Aweber API via the gem and we seem to be hitting the API Rate Limit a lot and we're only making calls like the following:

oauth = AWeber::OAuth.new(ENV['AWEBER_KEY'], ENV['AWEBER_SECRET'])
oauth.authorize_with_access('...', '...')

aweber = AWeber::Base.new(oauth)
list   = aweber.account.lists.find_by_name("some_list")

if list.subscribers.find_by_email('foo@bar.com').empty?
  list.subscribers.create({ ... })
end

We're getting a lot of very slow queries to Aweber from code like this. I can't see where the loop is but NewRelic is reporting that there are in some cases 30-40 calls made to /subscribers here.

36 more calls to Net::HTTP[https://api.aweber.com/1.0/accounts/.../lists/.../subscribers]: GET

Each call is also taking 1-2 seconds which is adding up to a very slow API call to get a list by a name and find a subscriber by an email. I hope those aren't looping over the subscribers when all were doing is calling find_by_email... right? That's not fetching all subscribers and then filtering in memory is it?

I would think find_by_name would be a search query to the server using something like the "find" method of the API. https://labs.aweber.com/docs/reference/1.0#subscriber_collection-find

vrajmohan commented 8 years ago

Sorry to hear that you are hitting performance and rate limit issues when you use the API. Unfortunately, the Ruby library has not been updated to reflect the find endpoint and does indeed fetch all the subscribers and filter them on the client side.

A workaround for you would be:

oauth = AWeber::OAuth.new(ENV['AWEBER_KEY'], ENV['AWEBER_SECRET'])
oauth.authorize_with_access('...', '...')

aweber = AWeber::Base.new(oauth)
list   = aweber.account.lists.find_by_name("some_list")

if aweber.get(list.subscribers_collection_link() + '?ws.op=find&email=foo@bar.com').empty?
  list.subscribers.create({ ... })
end

Please let us know if this works for you.

vrajmohan commented 8 years ago

You can also ignore the check as the subscribers to a list are guaranteed to have distinct emails. You will get back an error response if the subscriber you are trying to add already exists.

rmontgomery429 commented 8 years ago

@vrajmohan Thank you for your response. Are there any planned updates coming for this gem?