1

So, I'm trying to build a small rails app for internal use at the small design/dev agency I work for. I'm pretty new to rails (I'm a front-end dev) but I'm learning.

The goal is for the app to pull in data from Harvest and display daily/weekly/monthly hours worked for each of the 10 employees, as well as other info such as whether they are currently active and what percent of their work has been billable. The info should update about every minute.

I just need some advice on what the best practice is for structuring this project, since most of the data i'm working with will come from an external source. I initially tried just storing a name, email, and harvest id for each user in my pg database, and then using the harvest_id as a reference to query Harvest for the data I need. Here's an example of how I'm grabbing work reports:

    def harvest_user
      harvest.users.find(self.harvest_id)
    end


    def entries(interval, billable)
      user = self.harvest_user
      entries = harvest.reports.time_by_user(user, interval, DateTime.now, billable)
      sum = 0
      entries.each do |entry|
        hrs = entry.hours.to_s.to_f
        sum += hrs
      end
      sum.round(1)
    end

I'm then updating the data every minute by making an ajax call to the partial rendering the data.

Everything works properly, but the initial page load is really really slow, so I assume I must be doing something wrong.

Any advice? I feel like I can kind of grab at some ideas about making one big api call and then filtering through that data as needed, but I'm not really sure where to start.

Thanks!

  • 2
    You should check the terms of service on Harvest's api - polling them every minute seems heavy, and may violate their TOS. I'd suggest updating data from them once in a while (as infrequently as you can get away with), and caching that data for your users. – GreyBeardedGeek Jan 07 '13 at 01:39
  • agree with GreyBeardedGeek, once a min way to heavy, midnight daily if you need new figures every day? – Richlewis Jan 07 '13 at 08:24
  • I need new data pretty frequently, and we already have a basic implementation that does this (every 90 seconds I think), but I'm looking to rewrite the application because it was done sloppily. API limit is 100 calls/15 seconds I believe. http://www.getharvest.com/api – user1807510 Jan 07 '13 at 23:43

0 Answers0