Permalink
Browse files

* rake populate_authors does an initial scan of gems already in the r…

…ubygems table and populates the author relationships.

* Renamed User to Author. Reflected in existing migrations
* Deleted rename migrations since they haven't been committed to production.
* validates_uniqueness_of on Author#name, find before create on Rubygem method.
  • Loading branch information...
1 parent f6ee947 commit e1789a8020379aa796752409e3bdce28ac377dea Erik Hollensbe committed May 3, 2011
View
@@ -11,7 +11,7 @@ gem 'kaminari'
group :development, :test do
gem "rails3-generators"
- gem 'webmock'
+ #gem 'webmock'
gem 'cucumber-rails'
gem 'factory_girl_rails'
gem 'rspec-rails'
View
@@ -34,7 +34,6 @@ GEM
activemodel (= 3.0.7)
activesupport (= 3.0.7)
activesupport (3.0.7)
- addressable (2.2.5)
arel (2.0.9)
builder (2.1.2)
capistrano (2.5.21)
@@ -43,7 +42,6 @@ GEM
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.0.0)
- crack (0.1.8)
cucumber (0.10.2)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
@@ -128,9 +126,6 @@ GEM
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.26)
- webmock (1.6.2)
- addressable (>= 2.2.2)
- crack (>= 0.1.7)
PLATFORMS
ruby
@@ -148,4 +143,3 @@ DEPENDENCIES
rails3-generators
rspec-rails
tinyatom
- webmock
View
@@ -1,7 +1,8 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
-require File.expand_path('../config/application', __FILE__)
+$:.unshift File.expand_path('..', __FILE__)
+require 'config/application'
require 'rake'
GemTesters::Application.load_tasks
View
@@ -0,0 +1,7 @@
+class Author < ActiveRecord::Base
+ has_many :rubygems, through: :authorships
+ has_many :authorships
+
+ validates_presence_of :name
+ validates_uniqueness_of :name
+end
View
@@ -1,6 +1,6 @@
class Authorship < ActiveRecord::Base
belongs_to :rubygem
- belongs_to :author, class_name: 'User'
+ belongs_to :author
validates_presence_of :author_id, :rubygem_id
end
View
@@ -10,7 +10,7 @@ class Rubygem < ActiveRecord::Base
has_many :test_results
has_many :versions
- has_many :authors, through: :authorships, class_name: 'User'
+ has_many :authors, through: :authorships
has_many :authorships
def pass_count
@@ -23,12 +23,16 @@ def fail_count
def retrieve_authors
data = GemCutter.gem_data self.name
- authors = data['authors'].split(',').collect { |author| User.new(name: author.strip) }
+ authors = data['authors'].split(/\s*,\s*/).collect do |author|
+ author = author.strip
+ Author.find_by_name(author.strip) || Author.new(name: author.strip)
+ end
+
self.authors = authors
+ save
end
def latest_version
self.versions.sort.last
end
-
end
View
@@ -1,6 +0,0 @@
-class User < ActiveRecord::Base
- has_many :rubygems, through: :ownerships
- has_many :authorships
-
- validates_presence_of :name
-end
View
@@ -26,9 +26,9 @@ class Application < Rails::Application
end
config.middleware.use ExceptionNotifier,
- :email_prefix => "[Gem-Testers Exception] ",
- :sender_address => %{"Support" <support@gem-testers.org>},
- :exception_recipients => %w{erik@hollensbe.org bluepojo@gmail.com} if Rails.env == 'production'
+ :email_prefix => "[Gem-Testers Exception] ",
+ :sender_address => %{"Support" <support@gem-testers.org>},
+ :exception_recipients => %w{erik@hollensbe.org bluepojo@gmail.com} if Rails.env == 'production'
config.middleware.use DomainRedirector if Rails.env == 'production'
end
@@ -0,0 +1,12 @@
+class CreateAuthors < ActiveRecord::Migration
+ def self.up
+ create_table :authors do |t|
+ t.string :name, null: false
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :users
+ end
+end
@@ -1,13 +0,0 @@
-class CreateUsers < ActiveRecord::Migration
- def self.up
- create_table :users do |t|
- t.string :handle, null: false
-
- t.timestamps
- end
- end
-
- def self.down
- drop_table :users
- end
-end
@@ -1,7 +1,7 @@
class CreateAuthorships < ActiveRecord::Migration
def self.up
create_table :authorships do |t|
- t.integer :user_id, null: false
+ t.integer :author_id, null: false
t.integer :rubygem_id, null: false
t.timestamps
@@ -1,9 +0,0 @@
-class RenameHandleToNameInUsers < ActiveRecord::Migration
- def self.up
- rename_column :users, :handle, :name
- end
-
- def self.down
- rename_column :users, :name, :handle
- end
-end
@@ -1,9 +0,0 @@
-class RenameUserIdToAuthorIdInAuthorships < ActiveRecord::Migration
- def self.up
- rename_column :authorships, :user_id, :author_id
- end
-
- def self.down
- rename_column :authorships, :author_id, :user_id
- end
-end
View
@@ -10,7 +10,13 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110502204403) do
+ActiveRecord::Schema.define(:version => 20110423221836) do
+
+ create_table "authors", :force => true do |t|
+ t.string "name", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
create_table "authorships", :force => true do |t|
t.integer "author_id", :null => false
@@ -43,12 +49,6 @@
t.string "rubygems_test_version"
end
- create_table "users", :force => true do |t|
- t.string "name", :null => false
- t.datetime "created_at"
- t.datetime "updated_at"
- end
-
create_table "versions", :force => true do |t|
t.string "number", :null => false
t.integer "rubygem_id", :null => false
@@ -0,0 +1,42 @@
+desc "Populate the users and authors table with json data from gemcutter."
+task :populate_authors do
+ # change to use less or more threads -- be mindful of the traffic you'll generate!
+ threads = 5
+
+ require 'thread'
+ require 'config/environment'
+ require 'gem_cutter'
+ require 'pp'
+ gems = Rubygem.all.to_a
+
+ length = (gems.length / threads).floor
+
+ gems_p = []
+
+ threads.times do |x|
+ offset = length * x
+ gems_p.push gems[offset..(length*(x+1))-1].compact
+ end
+
+ gems_p[0] += gems[(length*threads)..-1]
+
+ puts_mutex = Mutex.new
+
+ pool = []
+
+ threads.times do |thread_num|
+ pool.push(
+ Thread.new do
+ gems_p[thread_num].each do |this_gem|
+ puts_mutex.synchronize do
+ puts "Processing #{this_gem.name}"
+ end
+
+ this_gem.retrieve_authors
+ end
+ end
+ )
+ end
+
+ pool.map(&:join)
+end

0 comments on commit e1789a8

Please sign in to comment.