summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/projects/graphs_controller.rb14
-rw-r--r--app/models/repository.rb8
-rw-r--r--app/views/projects/graphs/show.js.haml31
3 files changed, 36 insertions, 17 deletions
diff --git a/app/controllers/projects/graphs_controller.rb b/app/controllers/projects/graphs_controller.rb
index 5ff330ba6ca..252d47d939e 100644
--- a/app/controllers/projects/graphs_controller.rb
+++ b/app/controllers/projects/graphs_controller.rb
@@ -8,10 +8,18 @@ class Projects::GraphsController < Projects::ApplicationController
respond_to do |format|
format.html
format.js do
- @repo = @project.repository
- @stats = Gitlab::Git::GitStats.new(@repo.raw, @repo.root_ref)
- @log = @stats.parsed_log.to_json rescue []
+ fetch_graph
end
end
end
+
+ private
+
+ def fetch_graph
+ @log = @project.repository.graph_log.to_json
+ @success = true
+ rescue => ex
+ @log = []
+ @success = false
+ end
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index daf176576ad..4b8dee4829b 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -61,6 +61,14 @@ class Repository
Rails.cache.delete(cache_key(:size))
Rails.cache.delete(cache_key(:branch_names))
Rails.cache.delete(cache_key(:tag_names))
+ Rails.cache.delete(cache_key(:graph_log))
+ end
+
+ def graph_log
+ Rails.cache.fetch(cache_key(:graph)) do
+ stats = Gitlab::Git::GitStats.new(raw, root_ref)
+ stats.parsed_log
+ end
end
def cache_key(type)
diff --git a/app/views/projects/graphs/show.js.haml b/app/views/projects/graphs/show.js.haml
index b7c9b4113e9..43e776e5330 100644
--- a/app/views/projects/graphs/show.js.haml
+++ b/app/views/projects/graphs/show.js.haml
@@ -1,16 +1,19 @@
-:plain
- controller = new ContributorsStatGraph
- controller.init(#{@log})
+- if @success
+ :plain
+ controller = new ContributorsStatGraph
+ controller.init(#{@log})
- $("select").change( function () {
- var field = $(this).val()
- controller.set_current_field(field)
- controller.redraw_master()
- controller.redraw_authors()
- })
-
- $("#brush_change").change( function () {
- controller.change_date_header()
- controller.redraw_authors()
- })
+ $("select").change( function () {
+ var field = $(this).val()
+ controller.set_current_field(field)
+ controller.redraw_master()
+ controller.redraw_authors()
+ })
+ $("#brush_change").change( function () {
+ controller.change_date_header()
+ controller.redraw_authors()
+ })
+- else
+ :plain
+ $('.stat-graph').replaceWith('<div class="alert alert-error">Failed to load graph</div>')