Commit f1e0d37b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Its better to load graph with ajax since it requires ~10 seconds for bigger projects to finish up

parent 64457799
...@@ -23,7 +23,7 @@ gem 'omniauth-github' ...@@ -23,7 +23,7 @@ gem 'omniauth-github'
# Extracting information from a git repository # Extracting information from a git repository
# Provide access to Gitlab::Git library # Provide access to Gitlab::Git library
gem 'gitlab_git', '~> 1.2.1' gem 'gitlab_git', '~> 1.3.0'
# Ruby/Rack Git Smart-HTTP Server Handler # Ruby/Rack Git Smart-HTTP Server Handler
gem 'gitlab-grack', '~> 1.0.0', require: 'grack' gem 'gitlab-grack', '~> 1.0.0', require: 'grack'
......
...@@ -164,7 +164,7 @@ GEM ...@@ -164,7 +164,7 @@ GEM
gitlab-pygments.rb (0.3.2) gitlab-pygments.rb (0.3.2)
posix-spawn (~> 0.3.6) posix-spawn (~> 0.3.6)
yajl-ruby (~> 1.1.0) yajl-ruby (~> 1.1.0)
gitlab_git (1.2.1) gitlab_git (1.3.0)
activesupport (~> 3.2.13) activesupport (~> 3.2.13)
github-linguist (~> 2.3.4) github-linguist (~> 2.3.4)
gitlab-grit (~> 2.5.1) gitlab-grit (~> 2.5.1)
...@@ -543,7 +543,7 @@ DEPENDENCIES ...@@ -543,7 +543,7 @@ DEPENDENCIES
gitlab-gollum-lib (~> 1.0.0) gitlab-gollum-lib (~> 1.0.0)
gitlab-grack (~> 1.0.0) gitlab-grack (~> 1.0.0)
gitlab-pygments.rb (~> 0.3.2) gitlab-pygments.rb (~> 0.3.2)
gitlab_git (~> 1.2.1) gitlab_git (~> 1.3.0)
gitlab_meta (= 5.0) gitlab_meta (= 5.0)
gitlab_omniauth-ldap (= 1.0.2) gitlab_omniauth-ldap (= 1.0.2)
gon gon
......
class StatGraphController < ProjectResourceController class StatGraphController < ProjectResourceController
# Authorize # Authorize
before_filter :authorize_read_project! before_filter :authorize_read_project!
before_filter :authorize_code_access! before_filter :authorize_code_access!
before_filter :require_non_empty_project before_filter :require_non_empty_project
def show def show
respond_to do |format|
format.html
format.js do
@repo = @project.repository @repo = @project.repository
@stats = Gitlab::GitStats.new(@repo.raw, @repo.root_ref) @stats = Gitlab::Git::GitStats.new(@repo.raw, @repo.root_ref)
@log = @stats.parsed_log.to_json @log = @stats.parsed_log.to_json
end end
end
end
end end
.header.clearfix .loading-graph
%center
.loading
%h3.page_title Building repository graph. Please wait a moment.
.stat-graph
.header.clearfix
.right .right
%select %select
%option{:value => "commits"} Commits %option{:value => "commits"} Commits
...@@ -6,24 +12,20 @@ ...@@ -6,24 +12,20 @@
%option{:value => "deletions"} Deletions %option{:value => "deletions"} Deletions
%h3#date_header %h3#date_header
%input#brush_change{:type => "hidden"} %input#brush_change{:type => "hidden"}
.graphs
.graphs
#contributors-master #contributors-master
#contributors.clearfix #contributors.clearfix
%ol.contributors-list.clearfix %ol.contributors-list.clearfix
:javascript :javascript
controller = new ContributorsStatGraph $(".stat-graph").hide();
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 () { $.ajax({
controller.change_date_header() type: "GET",
controller.redraw_authors() url: location.href,
}) complete: function() {
\ No newline at end of file $(".loading-graph").hide();
$(".stat-graph").show();
},
dataType: "script"
});
: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()
})
Feature: Project Graph
Background:
Given I sign in as a user
And I own project "Shop"
And I visit project "Shop" graph page
@javascript
Scenario: I should see project graphs
Then page should have graphs
class ProjectGraph < Spinach::FeatureSteps
include SharedAuthentication
include SharedProject
Then 'page should have graphs' do
page.should have_selector ".stat-graph"
end
When 'I visit project "Shop" graph page' do
project = Project.find_by_name("Shop")
visit project_stat_graph_path(project, "master")
end
end
require 'gitlab/git_stats_log_parser'
module Gitlab
class GitStats
attr_accessor :repo, :ref
def initialize repo, ref
@repo, @ref = repo, ref
end
def log
args = ['--format=%aN%x0a%ad', '--date=short', '--shortstat', '--no-merges']
repo.git.run(nil, 'log', nil, {}, args)
end
def parsed_log
LogParser.parse_log(log)
end
end
end
class LogParser
#Parses the log file into a collection of commits
#Data model: {author, date, additions, deletions}
def self.parse_log log_from_git
log = log_from_git.split("\n")
i = 0
collection = []
entry = {}
while i <= log.size do
pos = i % 4
case pos
when 0
unless i == 0
collection.push(entry)
entry = {}
end
entry[:author] = log[i].to_s
when 1
entry[:date] = log[i].to_s
when 3
changes = log[i].split(",")
entry[:additions] = changes[1].to_i unless changes[1].nil?
entry[:deletions] = changes[2].to_i unless changes[2].nil?
end
i += 1
end
collection
end
end
\ No newline at end of file
require 'spec_helper'
require 'gitlab/git_stats_log_parser'
describe LogParser do
describe "#self.parse_log" do
context "log_from_git is a valid log" do
it "returns the correct log" do
fake_log = "Karlo Soriano
2013-05-09
14 files changed, 471 insertions(+)
Dmitriy Zaporozhets
2013-05-08
1 file changed, 6 insertions(+), 1 deletion(-)
Dmitriy Zaporozhets
2013-05-08
6 files changed, 19 insertions(+), 3 deletions(-)
Dmitriy Zaporozhets
2013-05-08
3 files changed, 29 insertions(+), 3 deletions(-)";
lp = LogParser.parse_log(fake_log)
lp.should eq([
{author: "Karlo Soriano", date: "2013-05-09", additions: 471},
{author: "Dmitriy Zaporozhets", date: "2013-05-08", additions: 6, deletions: 1},
{author: "Dmitriy Zaporozhets", date: "2013-05-08", additions: 19, deletions: 3},
{author: "Dmitriy Zaporozhets", date: "2013-05-08", additions: 29, deletions: 3}])
end
end
end
end
\ No newline at end of file
require 'spec_helper'
describe Gitlab::GitStats do
describe "#parsed_log" do
let(:stats) { Gitlab::GitStats.new(nil, nil) }
before(:each) do
stats.stub(:log).and_return("anything")
end
context "LogParser#parse_log returns 'test'" do
it "returns 'test'" do
LogParser.stub(:parse_log).and_return("test")
stats.parsed_log.should eq("test")
end
end
end
describe "#log" do
let(:repo) { Repository.new(nil, nil) }
let(:gs) { Gitlab::GitStats.new(repo.raw, repo.root_ref) }
before(:each) do
repo.stub(:raw).and_return(nil)
repo.stub(:root_ref).and_return(nil)
repo.raw.stub(:git)
end
context "repo.git.run returns 'test'" do
it "returns 'test'" do
repo.raw.git.stub(:run).and_return("test")
gs.log.should eq("test")
end
end
end
end
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment