Commit dc917552641f88defa77f3ac7d68312ccccd21c4

Authored by Dmitriy Zaporozhets
1 parent 367a5d1b

Cache graph log

app/controllers/projects/graphs_controller.rb
... ... @@ -8,10 +8,18 @@ class Projects::GraphsController < Projects::ApplicationController
8 8 respond_to do |format|
9 9 format.html
10 10 format.js do
11   - @repo = @project.repository
12   - @stats = Gitlab::Git::GitStats.new(@repo.raw, @repo.root_ref)
13   - @log = @stats.parsed_log.to_json rescue []
  11 + fetch_graph
14 12 end
15 13 end
16 14 end
  15 +
  16 + private
  17 +
  18 + def fetch_graph
  19 + @log = @project.repository.graph_log.to_json
  20 + @success = true
  21 + rescue => ex
  22 + @log = []
  23 + @success = false
  24 + end
17 25 end
... ...
app/models/repository.rb
... ... @@ -61,6 +61,14 @@ class Repository
61 61 Rails.cache.delete(cache_key(:size))
62 62 Rails.cache.delete(cache_key(:branch_names))
63 63 Rails.cache.delete(cache_key(:tag_names))
  64 + Rails.cache.delete(cache_key(:graph_log))
  65 + end
  66 +
  67 + def graph_log
  68 + Rails.cache.fetch(cache_key(:graph)) do
  69 + stats = Gitlab::Git::GitStats.new(raw, root_ref)
  70 + stats.parsed_log
  71 + end
64 72 end
65 73  
66 74 def cache_key(type)
... ...
app/views/projects/graphs/show.js.haml
1   -:plain
2   - controller = new ContributorsStatGraph
3   - controller.init(#{@log})
  1 +- if @success
  2 + :plain
  3 + controller = new ContributorsStatGraph
  4 + controller.init(#{@log})
4 5  
5   - $("select").change( function () {
6   - var field = $(this).val()
7   - controller.set_current_field(field)
8   - controller.redraw_master()
9   - controller.redraw_authors()
10   - })
11   -
12   - $("#brush_change").change( function () {
13   - controller.change_date_header()
14   - controller.redraw_authors()
15   - })
  6 + $("select").change( function () {
  7 + var field = $(this).val()
  8 + controller.set_current_field(field)
  9 + controller.redraw_master()
  10 + controller.redraw_authors()
  11 + })
16 12  
  13 + $("#brush_change").change( function () {
  14 + controller.change_date_header()
  15 + controller.redraw_authors()
  16 + })
  17 +- else
  18 + :plain
  19 + $('.stat-graph').replaceWith('<div class="alert alert-error">Failed to load graph</div>')
... ...