irb(main):013:0> app.get '/explore'Started GET "/explore" for 127.0.0.1 at 2015-07-16 14:34:32 +0000Processing by Explore::ProjectsController#trending as HTMLCompleted 200 OK in 33080ms (Views: 32368.8ms | ActiveRecord: 631.5ms)=> 200
@dzaporozhets I think if you add a check to only get projects that had activity in the last month to that statement it should already be much faster :)
We have the field last_activity_at in the project so it's a simple where statement.
Ok its not about SQL. Although sql is not super efficient it takes only 1% of page load time. The rest is taken by template. Possibly by commit_count method. Recently few projects appeared on trending page with 200K commits and it was a reason of timeout. It was git trying to count all commits of 20 projects on trending page.
@dzaporozhets can we change it to use git rev-list HEAD --count to get the commit count of a repo?
That command seems to have a cache. I tested it on the linux mainline repo with 495570 commits.
The first run took ~20 seconds, all following calls took ~5 seconds.
Another option would be to change the text a bit and limit it to commits this year with something like :
git rev-list HEAD --count --after="2014-07-27 13:37"
That command takes less than a second for the linux kernel for me and still returns ~30000 commits.
edit:
Personaly I like my second suggestion more. For trending projects you don't really need to see the total commits.
It would be enough to show the commits in one year to see how active a project is.
@haynes thats the problem we had at explore page. 2 repos were enough to get timeout
Another option would be to change the text a bit and limit it to commits this year
makes no sense to me. I want to know total commit count.
That command seems to have a cache
Yes but it get cleared on each push and not build until user visit page. I am going to implement cache build in background after each push. In this case even if it takes 20 seconds - its ok. And user will get cached information
@dzaporozhets I understand.
Another option would be to save the total number of commits in the project model on push.
Not sure if that still makes sense when the cache is implemented.
Won't the cache get pretty big when it caches a lot of big repos?