amalc / rubyzoho

Abstracting Zoho’s API into a set of Ruby classes, with reflection of Zoho’s fields using a more familiar ActiveRecord lifecycle, but without ActiveRecord. Works with Rails and Devise.
MIT License
62 stars 57 forks source link

Smashed my API limit! #26

Closed christhesoul closed 9 years ago

christhesoul commented 10 years ago

I have managed to completely crush my Zoho API limit today. Although I'm not exactly sure how or why.

I only use the gem for getting, and do so in its own class. Like so:

class Zoho
  def self.all_accounts
    Rails.cache.fetch('zoho_accounts') { RubyZoho::Crm::Account.all }
  end
end

I then do stuff using Zoho.all_accounts which presumably looks at the cache and avoids the API call.

The only other place I use it is in some tests:

  before(:each) do
    RubyZoho::Crm::Account.any_instance.stub(:account_name).and_return("ABC Widgets")
    RubyZoho::Crm::Account.any_instance.stub(:accountid).and_return(1)
  end

Will either of these make the excessive API calls that would cause a relatively small app to smash the Zoho limits?

Any advice would be sincerely appreciated.

Thanks!

amalc commented 10 years ago

Apologies for not responding sooner. I'm traveling at the moment but will take a look. Which type of Zoho account are you using?

gbusker commented 10 years ago

I have the same issue especially when I do a lot of restarts during development. The issue really is that zoho connects and does a few API calls from the initializer which is maybe a bit too enthusiastic.

In my test suite I have mocked the CRM calls so no calls go out to the real API and in development I now just don't do any API calls.

amalc commented 10 years ago

@gbusker Possible to send through a PR with those mocks? Sound like a terrific enhancement for dev.

amalc commented 10 years ago

@christhesoul Accounts.all can be quite expensive in API calls because I think Zoho charges those to the top level limit. Do you do that once a day? We cache above the gem. I suppose the timing depends on your use case.

tylerdavis commented 10 years ago

I'm doing nothing but initializing and configuring my connection seen below in my rails app:

require 'ruby_zoho'

RubyZoho.configure do |config|
  config.api_key = '01441e437367c4be6f1a888asd3e1d6f3ab'
  config.crm_modules = ['Leads']
end

And this action alone is making 13 requests to my crm instance. That's before I even attempt a query.

amalc commented 10 years ago

Do you see the same behavior after initialization? The Zoho API, as written requires separate calls to inflect the fields for each module. Although with just leads configured, I expect to see less than that.

Can you turn on the trace and upload the log?

On Mon, Jun 2, 2014 at 12:35 PM, Tyler Davis notifications@github.com wrote:

I'm doing nothing but initializing and configuring my connection seen below in my rails app:

require 'ruby_zoho' RubyZoho.configure do |config| config.api_key = '01441e437367c4be6f1a8883e1d6f3ab' config.crm_modules = ['Leads']end

And this action alone is making 13 requests to my crm instance. That's before I even attempt a query.

— Reply to this email directly or view it on GitHub https://github.com/amalc/rubyzoho/issues/26#issuecomment-44860307.

JunichiIto commented 9 years ago

I had the same issue.

I was surprised at receiving "Zoho Error Code 4421: You crossed your license limit."

In my case, it seems RSpec test suites, that is, frequent restarting were silently consuming API limit. It was very hard to find the root cause.

I hope this issue would get fixed soon.

florian2 commented 9 years ago

Just for the record, we have the same problem.

in our case, we have rake tasks that of course start the rails-environment every 15 minutes :(

amalc commented 9 years ago

@florian2 @JunichiIto Do you have any ideas about this? It's not obvious what the best option here is. Could just add a configuration option which just has the gem do nothing when its running in a test environment. But that will more than likely break any tests you've got. I've just added VCR to the gem to test without having to call the Zoho API and it works well. Would that option work for you? You'll need to add VCR to your code and wrap the tests with the VCR block.

florian2 commented 9 years ago

we ended up writing our own api-client for zoho crm. i think the concept, that for every reloading / starting of the environment this gem makes calls to zoho to (i guess) fetch the actual "structure" of the zoho objects is the root cause here. it adds up over a day. adding vcr for testing env is always a good idea :)

amalc commented 9 years ago

@florian2 It can, yes. We use this feature to reduce to calls during development and testing.

RubyZoho.configure do |config|
  # Other stuff for initialization
  config.cache_fields = true
end
amalc commented 9 years ago

FYI. A new version of the gem 0.5.0 switches to the newer Zoho search API. This effectively raises the number of API calls used in a day because search are no longer accounted for separately. I'm going to close this issue out. Re-open if somebody has an idea of how to test which can be incorporated into the gem. Thanks.