Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/git/git-scm.com.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbry4n <bryann83@gmail.com>2014-07-29 08:04:59 +0400
committerbry4n <bryann83@gmail.com>2014-07-29 08:04:59 +0400
commit6720481ba62ecf7c5c1c7d6ebe928292f5cd024a (patch)
treeff0f0356ffaf107884250f957f80471e802f9c39
parent31aba3c9017b7d45c3a094cc4aaeb83cd7a3753b (diff)
Add performance test for doc#man and refactor version_changes for performance
-rw-r--r--Gemfile4
-rw-r--r--Gemfile.lock10
-rw-r--r--app/models/doc.rb26
-rw-r--r--app/models/doc_version.rb46
-rw-r--r--db/schema.rb17
-rwxr-xr-xscript/benchmark9
-rwxr-xr-xscript/rebuild5
-rw-r--r--spec/spec_helper.rb4
-rw-r--r--test/performance/browsing_doc_test.rb29
-rw-r--r--test/performance/browsing_test.rb12
-rw-r--r--test/test_helper.rb1
11 files changed, 100 insertions, 63 deletions
diff --git a/Gemfile b/Gemfile
index 6b2c7a31..a73865e4 100644
--- a/Gemfile
+++ b/Gemfile
@@ -47,7 +47,8 @@ end
group :development, :test do
gem 'dotenv-rails'
gem "sqlite3"
-# gem "debugger"
+ gem 'byebug'
+ gem 'ruby-prof'
end
group :test do
@@ -56,4 +57,5 @@ group :test do
gem 'rspec-rails'
gem 'shoulda-matchers'
gem 'webmock'
+ gem 'rails-perftest'
end
diff --git a/Gemfile.lock b/Gemfile.lock
index ca262043..0ce91b1a 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -38,6 +38,9 @@ GEM
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
+ byebug (3.1.2)
+ columnize (~> 0.8)
+ debugger-linecache (~> 1.2)
chunky_png (1.3.1)
coderay (1.1.0)
coffee-rails (4.0.1)
@@ -47,6 +50,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.7.1)
+ columnize (0.8.9)
commonjs (0.2.7)
compass (0.12.7)
chunky_png (~> 1.2)
@@ -59,6 +63,7 @@ GEM
dalli (2.7.2)
database_cleaner (1.3.0)
debug_inspector (0.0.2)
+ debugger-linecache (1.2.0)
diff-lcs (1.2.5)
dotenv (0.11.1)
dotenv-deployment (~> 0.0.2)
@@ -126,6 +131,7 @@ GEM
bundler (>= 1.3.0, < 2.0)
railties (= 4.1.4)
sprockets-rails (~> 2.0)
+ rails-perftest (0.0.4)
rails_12factor (0.0.2)
rails_serve_static_assets
rails_stdout_logging
@@ -161,6 +167,7 @@ GEM
rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.3)
+ ruby-prof (0.15.1)
rubyzip (1.1.6)
safe_yaml (1.0.3)
sass (3.2.19)
@@ -231,6 +238,7 @@ DEPENDENCIES
awesome_print
better_errors
binding_of_caller
+ byebug
coffee-rails
compass-rails
dalli
@@ -254,9 +262,11 @@ DEPENDENCIES
pg
rack-timeout
rails (= 4.1.4)
+ rails-perftest
rails_12factor
redcarpet
rspec-rails
+ ruby-prof
rubyzip
sass-rails (= 4.0.3)
shoulda-matchers
diff --git a/app/models/doc.rb b/app/models/doc.rb
index 8d5d8ffa..16c07893 100644
--- a/app/models/doc.rb
+++ b/app/models/doc.rb
@@ -12,30 +12,4 @@ class Doc < ActiveRecord::Base
has_many :doc_versions
- # returns an array of the differences with 3 entries
- # 0: additions
- # 1: subtractions
- # 2: 8 - (add + sub)
- def self.get_diff(sha_to, sha_from)
- key = "diff-#{sha_to}-#{sha_from}"
- doc_to = Doc.where(:blob_sha => sha_to).first.plain.split("\n")
- doc_from = Doc.where(:blob_sha => sha_from).first.plain.split("\n")
- diff = Diff::LCS.diff(doc_to, doc_from)
- total = adds = mins = 0
- diff.first.each do |change|
- adds += 1 if change.action == '+'
- mins += 1 if change.action == '-'
- total += 1
- end
- if total > 8
- min = (8.0 / total)
- adds = (adds * min).floor
- mins = (mins * min).floor
- [adds, mins, (8 - total)]
- else
- [adds, mins, (8 - total)]
- end
- rescue
- [0, 0, 8]
- end
end
diff --git a/app/models/doc_version.rb b/app/models/doc_version.rb
index 392ac1cf..1a4b6d45 100644
--- a/app/models/doc_version.rb
+++ b/app/models/doc_version.rb
@@ -22,8 +22,8 @@ class DocVersion < ActiveRecord::Base
for_doc(doc_name).joins([:version, :doc]).where('docs.blob_sha = ?', sha).order('versions.vorder').first
end
- def self.latest_versions(doc_name)
- for_doc(doc_name).includes(:version).order('versions.vorder DESC')
+ def self.latest_versions(doc_name, size=20)
+ for_doc(doc_name).includes(:version).order('versions.vorder DESC').limit(size)
end
def self.for_version(doc_name, version_name)
@@ -33,13 +33,12 @@ class DocVersion < ActiveRecord::Base
def self.version_changes(file, size = 20)
versions = []
unchanged = []
- vers = DocVersion.latest_versions(file)
- (vers.size-2).times do |i|
- v = vers[i]
- prev = vers[i+1]
- sha2 = v.doc.blob_sha
+ vers = includes(:doc, :version).order("versions.vorder DESC").limit(size)
+ vers.each_with_index do |v, i|
+ next unless prev = vers[i+1]
sha1 = prev.doc.blob_sha
- if sha1 == sha2
+ sha2 = v.doc.blob_sha
+ if sha1 == sha2
unchanged << v.version.name
else
if unchanged.size > 0
@@ -49,11 +48,38 @@ class DocVersion < ActiveRecord::Base
versions << {:name => "#{unchanged.last} &rarr; #{unchanged.first} no changes", :changed => false}
end
unchanged = []
+ else
+ versions << {:name => v.version.name, :time => v.version.committed, :diff => v.diff(prev), :changed => true}
end
- versions << {:name => v.version.name, :time => v.version.committed, :diff => Doc.get_diff(sha2, sha1), :changed => true}
end
end
- versions[0,size]
+ versions
+ end
+
+ # returns an array of the differences with 3 entries
+ # 0: additions
+ # 1: subtractions
+ # 2: 8 - (add + sub)
+ def diff(doc_version)
+ begin
+ to = self.doc.plain.split("\n")
+ from = doc_version.doc.plain.split("\n")
+ total = adds = mins = 0
+ diff = Diff::LCS.diff(to, from)
+ diff.first.each do |change|
+ adds += 1 if change.action == "+"
+ mins += 1 if change.action == "-"
+ total += 1
+ end
+ if total > 8
+ min = (8.0 / total)
+ adds = (adds * min).floor
+ mins = (mins * min).floor
+ end
+ [adds, mins, (8 - total)]
+ rescue
+ [0, 0, 8]
+ end
end
def index
diff --git a/db/schema.rb b/db/schema.rb
index 4d62523d..10359179 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -13,16 +13,13 @@
ActiveRecord::Schema.define(version: 20121211011752) do
- # These are extensions that must be enabled in order to support this database
- enable_extension "plpgsql"
-
create_table "books", force: true do |t|
t.string "code"
t.datetime "created_at"
t.datetime "updated_at"
end
- add_index "books", ["code"], name: "index_books_on_code", using: :btree
+ add_index "books", ["code"], name: "index_books_on_code"
create_table "chapters", force: true do |t|
t.string "title"
@@ -33,7 +30,7 @@ ActiveRecord::Schema.define(version: 20121211011752) do
t.string "sha"
end
- add_index "chapters", ["book_id"], name: "index_chapters_on_book_id", using: :btree
+ add_index "chapters", ["book_id"], name: "index_chapters_on_book_id"
create_table "doc_files", force: true do |t|
t.string "name"
@@ -41,7 +38,7 @@ ActiveRecord::Schema.define(version: 20121211011752) do
t.datetime "updated_at"
end
- add_index "doc_files", ["name"], name: "index_doc_files_on_name", using: :btree
+ add_index "doc_files", ["name"], name: "index_doc_files_on_name"
create_table "doc_versions", force: true do |t|
t.integer "version_id"
@@ -59,7 +56,7 @@ ActiveRecord::Schema.define(version: 20121211011752) do
t.datetime "updated_at"
end
- add_index "docs", ["blob_sha"], name: "index_docs_on_blob_sha", using: :btree
+ add_index "docs", ["blob_sha"], name: "index_docs_on_blob_sha"
create_table "downloads", force: true do |t|
t.string "url"
@@ -94,8 +91,8 @@ ActiveRecord::Schema.define(version: 20121211011752) do
t.integer "number"
end
- add_index "sections", ["chapter_id"], name: "index_sections_on_chapter_id", using: :btree
- add_index "sections", ["slug"], name: "index_sections_on_slug", using: :btree
+ add_index "sections", ["chapter_id"], name: "index_sections_on_chapter_id"
+ add_index "sections", ["slug"], name: "index_sections_on_slug"
create_table "versions", force: true do |t|
t.string "name"
@@ -107,6 +104,6 @@ ActiveRecord::Schema.define(version: 20121211011752) do
t.float "vorder"
end
- add_index "versions", ["name"], name: "index_versions_on_name", using: :btree
+ add_index "versions", ["name"], name: "index_versions_on_name"
end
diff --git a/script/benchmark b/script/benchmark
new file mode 100755
index 00000000..d60c8c1d
--- /dev/null
+++ b/script/benchmark
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+dropdb gitscm_test
+
+createdb gitscm_test
+
+rake db:test:load
+
+rake test:benchmark
diff --git a/script/rebuild b/script/rebuild
index 2b84d9c4..72ed923b 100755
--- a/script/rebuild
+++ b/script/rebuild
@@ -2,7 +2,9 @@ script/bootstrap
export OLD_PWD=$PWD
export GIT_REPO=../git/.git
-rm db/*.sqlite3
+dropdb gitscm_development
+createdb gitscm_development
+
rake db:migrate
if [ -d "$GIT_REPO" ]; then
@@ -15,3 +17,4 @@ cd $OLD_PWD
# Build git docs
bundle exec rake local_index
+bundle exec rake remote_genbook
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index c65a5de6..5a3d4acd 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,8 +1,8 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
+
require 'rspec/rails'
-require 'rspec/autorun'
require 'database_cleaner'
require 'webmock/rspec'
@@ -45,7 +45,7 @@ RSpec.configure do |config|
# the seed, which is printed after each run.
# --seed 1234
# config.order = "random"
- config.treat_symbols_as_metadata_keys_with_true_values = true
+ # config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run focus: true
config.run_all_when_everything_filtered = true
end
diff --git a/test/performance/browsing_doc_test.rb b/test/performance/browsing_doc_test.rb
new file mode 100644
index 00000000..cda63a91
--- /dev/null
+++ b/test/performance/browsing_doc_test.rb
@@ -0,0 +1,29 @@
+require 'test_helper'
+require 'rails/performance_test_help'
+require "database_cleaner"
+class BrowsingDocTest < ActionDispatch::PerformanceTest
+ self.profile_options = {runs: 10, metrics: [:wall_time, :process_time]}
+
+ def setup
+ DatabaseCleaner.strategy = :truncation
+ DatabaseCleaner.clean
+ 100.times do |i|
+ tree_sha = SecureRandom.hex
+ commit_sha = SecureRandom.hex
+ ascii_sha = SecureRandom.hex
+ version = Version.create(name: "#{i}.0.0", commit_sha: commit_sha, tree_sha: tree_sha, committed: Time.current)
+ doc_file = DocFile.create(name: "git-config")
+ doc = Doc.create(blob_sha: ascii_sha, html: "test", plain: "test")
+ doc_version = DocVersion.create(version_id: version.id, doc_id: doc.id, doc_file_id: doc_file.id)
+ end
+ end
+
+ def teardown
+ DatabaseCleaner.clean
+ end
+
+ test "browsing git-config" do
+ get '/docs/git-config'
+ end
+
+end
diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb
deleted file mode 100644
index 3fea27b9..00000000
--- a/test/performance/browsing_test.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require 'test_helper'
-require 'rails/performance_test_help'
-
-class BrowsingTest < ActionDispatch::PerformanceTest
- # Refer to the documentation for all available options
- # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
- # :output => 'tmp/performance', :formats => [:flat] }
-
- def test_homepage
- get '/'
- end
-end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index cf2fcd2a..256bce25 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,7 +1,6 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
-require 'shoulda'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.