Revert "removed the pod_stats table (was the cause of bloat on the database)."
This reverts commit 902c40e42d.
This commit is contained in:
parent
902c40e42d
commit
0dfcbca51b
7 changed files with 61 additions and 25 deletions
|
|
@ -48,7 +48,10 @@ module Job
|
|||
end
|
||||
end
|
||||
unless response.success?
|
||||
pod = Pod.find_or_create_by_url(response.effective_url)
|
||||
log_line = "event=http_multi_fail sender_id=#{user_id} recipient_id=#{person.id} url=#{response.effective_url} response_code='#{response.code}'"
|
||||
Rails.logger.info(log_line)
|
||||
pod.pod_stats.create(:error_message => log_line, :person_id => person.id, :error_code => response.code.to_i)
|
||||
failed_request_people << person.id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
13
app/models/pod.rb
Normal file
13
app/models/pod.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class Pod < ActiveRecord::Base
|
||||
has_many :pod_stats
|
||||
|
||||
def self.find_or_create_by_url(url)
|
||||
u = URI.parse(url)
|
||||
pod = self.find_or_initialize_by_host(u.host)
|
||||
unless pod.persisted?
|
||||
pod.ssl = (u.scheme == 'https')? true : false
|
||||
pod.save
|
||||
end
|
||||
pod
|
||||
end
|
||||
end
|
||||
4
app/models/pod_stat.rb
Normal file
4
app/models/pod_stat.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
class PodStat < ActiveRecord::Base
|
||||
belongs_to :pod
|
||||
|
||||
end
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
class RemovePodStatsTable < ActiveRecord::Migration
|
||||
def self.up
|
||||
drop_table :pods
|
||||
drop_table :pod_stats
|
||||
end
|
||||
|
||||
def self.down
|
||||
create_table :pods do |t|
|
||||
t.string :host
|
||||
t.boolean :ssl
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :pod_stats do |t|
|
||||
t.integer :error_code
|
||||
t.integer :person_id
|
||||
t.text :error_message
|
||||
t.integer :pod_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
18
db/schema.rb
18
db/schema.rb
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20110830000140) do
|
||||
ActiveRecord::Schema.define(:version => 20110818212541) do
|
||||
|
||||
create_table "aspect_memberships", :force => true do |t|
|
||||
t.integer "aspect_id", :null => false
|
||||
|
|
@ -236,6 +236,22 @@ ActiveRecord::Schema.define(:version => 20110830000140) do
|
|||
add_index "people", ["guid"], :name => "index_people_on_guid", :unique => true
|
||||
add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true
|
||||
|
||||
create_table "pod_stats", :force => true do |t|
|
||||
t.integer "error_code"
|
||||
t.integer "person_id"
|
||||
t.text "error_message"
|
||||
t.integer "pod_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "pods", :force => true do |t|
|
||||
t.string "host"
|
||||
t.boolean "ssl"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "post_visibilities", :force => true do |t|
|
||||
t.integer "post_id", :null => false
|
||||
t.datetime "created_at"
|
||||
|
|
|
|||
19
spec/models/pod_spec.rb
Normal file
19
spec/models/pod_spec.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Pod do
|
||||
|
||||
it 'has many pod_stats' do
|
||||
Pod.new.pod_stats.should be_empty
|
||||
end
|
||||
describe '.find_or_create_by_url' do
|
||||
it 'takes a url, and makes one by host' do
|
||||
pod = Pod.find_or_create_by_url('https://joindiaspora.com/maxwell')
|
||||
pod.host.should == 'joindiaspora.com'
|
||||
end
|
||||
|
||||
it 'sets ssl boolean(side-effect)' do
|
||||
pod = Pod.find_or_create_by_url('https://joindiaspora.com/maxwell')
|
||||
pod.ssl.should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
5
spec/models/pod_stat_spec.rb
Normal file
5
spec/models/pod_stat_spec.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe PodStat do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Loading…
Reference in a new issue