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!