Skip to content

Commit 73fe695

Browse files
committedNov 15, 2014
Fixed error when creating teams
1 parent 07fa50d commit 73fe695

File tree

17 files changed

+118
-632
lines changed

17 files changed

+118
-632
lines changed
 

‎Rakefile

-278
Original file line numberDiff line numberDiff line change
@@ -4,281 +4,3 @@ require 'rake'
44
Coderwall::Application.load_tasks
55

66
task default: :spec
7-
8-
namespace :team do
9-
task migrate: :environment do
10-
puts '--- Beginning team migration ---'
11-
success = true
12-
begin
13-
Team.each do |team|
14-
begin
15-
puts ">>> Migrating #{team.id}"
16-
TeamMigratorJob.new.perform(team.id.to_s)
17-
rescue => ex
18-
success = false
19-
puts "[#{team.id.to_s}] #{ex} >>\n#{ex.backtrace.join("\n ")}"
20-
end
21-
end
22-
ensure
23-
puts "--- #{success ? 'Successful' : 'Unsuccessful'} team migration ---"
24-
end
25-
end
26-
27-
#
28-
# IMPORTANT: pending_join_requests is a STRING array in Postgres but an INTEGER array in MongoDB.
29-
# IMPORTANT: pending_join_requests is an array of User#id values
30-
#
31-
32-
task verify: :environment do
33-
#ActiveRecord::Base.logger = nil
34-
#Mongoid.logger = nil
35-
#Moped.logger = nil
36-
37-
PgTeam.find_each(batch_size: 100) do |pg_team|
38-
begin
39-
mongo_id = pg_team.mongo_id
40-
mongo_team = Team.find(mongo_id)
41-
42-
# Ignoring:
43-
# - updated_at
44-
45-
puts 'TEAM'
46-
47-
neq(:slug, pg_team, mongo_team, false)
48-
49-
neq_string(:pending_join_requests, pg_team, pg_team.pending_join_requests.map(&:to_i).sort.join(', '), mongo_team, mongo_team.pending_join_requests.map(&:to_i).sort.join(', '), false)
50-
51-
%i(score size total mean median).each do |attr|
52-
neq_dec(attr, pg_team, mongo_team, false)
53-
end
54-
55-
%i(about achievement_count analytics benefit_description_1 benefit_description_2 benefit_description_3 benefit_name_1 benefit_name_2 benefit_name_3 big_image big_quote blog_feed branding country_id created_at endorsement_count facebook featured_banner_image featured_links_title github github_organization_name headline hide_from_featured highlight_tags hiring_tagline interview_steps invited_emails link_to_careers_page location monthly_subscription name number_of_jobs_to_show office_photos organization_way organization_way_name organization_way_photo our_challenge paid_job_posts premium preview_code reason_description_1 reason_description_2 reason_description_3 reason_name_1 reason_name_2 reason_name_3 size stack_list twitter upcoming_events upgraded_at valid_jobs website why_work_image your_impact youtube_url).each do |attr|
56-
neq(attr, pg_team, mongo_team)
57-
end
58-
59-
# TODO: Account
60-
if mongo_team.account.present? && pg_team.account.blank?
61-
puts "account | pg:#{pg_team.id} | mongo:#{mongo_team.id}| The account was not migrated."
62-
end
63-
64-
if mongo_team.account.present? && pg_team.account.present?
65-
check_plans = %i(stripe_card_token stripe_customer_token admin_id).map do |attr|
66-
neq(attr, pg_team.account, mongo_team.account)
67-
end.any? { |x| !x }
68-
69-
# TODO: Plans
70-
if check_plans
71-
left = pg_team.account.plans.pluck(:id).sort
72-
right = mongo_team.account.plan_ids.sort
73-
74-
if left != right
75-
puts "account.plans | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{left} != #{right}"
76-
end
77-
end
78-
end
79-
80-
#puts 'LOCATIONS'
81-
82-
#pg_team_locations = pg_team.locations
83-
#mongo_team_locations = mongo_team.team_locations
84-
85-
#if mongo_team_locations.count != pg_team_locations.count
86-
#puts "locations | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{mongo_team_locations.count} != #{pg_team_locations.count}"
87-
#end
88-
89-
## Ignoring:
90-
## - points_of_interest
91-
#pg_team.locations.each do |pg_team_location|
92-
#mongo_team_location = mongo_team.team_locations.select { |tl| tl.name == pg_team_location.name }.first
93-
94-
#%i(address city country description name state_code).each do |attr|
95-
#neq(attr, pg_team_location, mongo_team_location, false)
96-
#end
97-
#end
98-
99-
100-
#puts 'LINKS'
101-
102-
pg_team_links = pg_team.links
103-
mongo_team_links = mongo_team.featured_links
104-
105-
if mongo_team_links.count != pg_team_links.count
106-
puts "links | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{mongo_team_links.count} != #{pg_team_links.count}"
107-
end
108-
109-
pg_team_links.each do |pg_team_link|
110-
mongo_team_link = mongo_team_links.select { |tl| tl.name == pg_team_link.name }.first
111-
112-
%i(url name).each do |attr|
113-
neq(attr, pg_team_link, mongo_team_link, false)
114-
end
115-
end
116-
117-
#puts 'MEMBERS'
118-
119-
if pg_team.members.count != mongo_team.team_members.count
120-
puts "members | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{pg_team.members.count} < #{mongo_team.team_members.count}"
121-
end
122-
123-
124-
#puts 'JOBS'
125-
126-
#pg_team.jobs.each do |pg_team_job|
127-
#mongo_team_job = Team.where(id: pg_team_job.team_document_id.to_s).first
128-
129-
#neq(:name, pg_team_job, mongo_team_job, false)
130-
#end
131-
132-
#puts 'FOLLOWERS'
133-
134-
pg_team.followers.each do |pg_team_follower|
135-
mongo_team_follower = Team.where(id: pg_team_follower.mongo_id.to_s).first
136-
# admins
137-
# editors
138-
%i(
139-
about
140-
achievement_count
141-
analytics
142-
benefit_description_1
143-
benefit_description_2
144-
benefit_description_3
145-
benefit_name_1
146-
benefit_name_2
147-
benefit_name_3
148-
big_image
149-
big_quote
150-
blog_feed
151-
branding
152-
country_id
153-
created_at
154-
endorsement_count
155-
facebook
156-
featured_banner_image
157-
featured_links_title
158-
github_organization_name
159-
headline
160-
hide_from_featured
161-
highlight_tags
162-
hiring_tagline
163-
interview_steps
164-
invited_emails
165-
link_to_careers_page
166-
location
167-
monthly_subscription
168-
name
169-
number_of_jobs_to_show
170-
office_photos
171-
organization_way
172-
organization_way_name
173-
organization_way_photo
174-
our_challenge
175-
paid_job_posts
176-
premium
177-
preview_code
178-
reason_description_1
179-
reason_description_2
180-
reason_description_3
181-
reason_name_1
182-
reason_name_2
183-
reason_name_3
184-
slug
185-
stack_list
186-
twitter
187-
upcoming_events
188-
upgraded_at
189-
valid_jobs
190-
website
191-
why_work_image
192-
your_impact
193-
youtube_url
194-
).each do |attr|
195-
neq(attr, pg_team_follower, mongo_team_follower, false)
196-
end
197-
neq_string(:pending_join_requests, pg_team_follower, pg_team_follower.pending_join_requests.map(&:to_i).sort.join(', '), mongo_team_follower, mongo_team_follower.pending_join_requests.map(&:to_i).sort.join(', '), false)
198-
199-
neq_string(:avatar, pg_team_follower, pg_team_follower.avatar.url, mongo_team_follower, mongo_team_follower.avatar.url, false)
200-
201-
%i(score size total mean median).each do |attr|
202-
neq_dec(attr, pg_team_follower, mongo_team_follower, false)
203-
end
204-
end
205-
206-
# TODO: Pending Requests
207-
end
208-
end
209-
end
210-
211-
def neq(attr, pg, mongo, fail_if_neq=true)
212-
left = pg.send(attr)
213-
right = mongo.send(attr)
214-
215-
if left != right
216-
puts "#{attr} | pg:#{pg.id} | mongo:#{mongo.id}| #{left} != #{right}"
217-
true
218-
else
219-
false
220-
end
221-
rescue => ex
222-
print_neq_error(ex)
223-
end
224-
225-
def neq_string(attr, pg, left, mongo, right, fail_if_neq=true)
226-
if left != right
227-
puts "#{attr} | pg:#{pg.id} | mongo:#{mongo.id}| #{left} != #{right}"
228-
true
229-
else
230-
false
231-
end
232-
rescue => ex
233-
print_neq_error(ex)
234-
end
235-
236-
def neq_dec(attr, pg, mongo, fail_if_neq=true)
237-
scale = 7
238-
239-
left = pg.send(attr).to_d.round(scale)
240-
right = mongo.send(attr).to_d.round(scale)
241-
242-
243-
if left != right
244-
puts "#{attr} | pg:#{pg.id} | mongo:#{mongo.id}| #{left} != #{right}"
245-
true
246-
else
247-
false
248-
end
249-
rescue => ex
250-
print_neq_error(ex)
251-
end
252-
253-
def print_neq_error(ex)
254-
puts '*'*80
255-
puts
256-
puts ex
257-
puts
258-
puts '-'*80
259-
puts
260-
ap ex.backtrace
261-
puts
262-
puts '*'*80
263-
end
264-
265-
task counts: :environment do
266-
pg_team_count = PgTeam.count
267-
puts "PgTeam.count=#{pg_team_count}"
268-
team_count = Team.count
269-
puts "Team.count=#{team_count}"
270-
puts "Unmigrated teams count=#{(team_count - pg_team_count)}"
271-
end
272-
273-
274-
task unmigrated: :environment do
275-
unmigrated_teams = []
276-
277-
Team.all.each do |team|
278-
unmigrated_teams << team.id.to_s unless PgTeam.where(mongo_id: team.id.to_s).exists?
279-
end
280-
281-
puts "Unmigrated teams count=#{unmigrated_teams.count}"
282-
puts "Unmigrated Teams=%w(#{unmigrated_teams.join(' ')})"
283-
end
284-
end

‎app/assets/javascripts/ember/templates/teams/show.js.hbs.hamlbars

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
%img.team-avatar{:bind => {:src => 'team.avatar'}}
66
%span=hb 'team.name'
77
%td.members.span3
8-
=hb 'each team.team_members' do
8+
=hb 'each team.members' do
99
%a{:bind => {:href => 'profile_path' }}
1010
%img.thumb{:bind => {:src => 'avatar'}}
1111
=hb 'if team.has_more_than_min_members' do

‎app/controllers/teams_controller.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ class TeamsController < ApplicationController
77

88
def index
99
current_user.seen(:teams) if signed_in?
10-
@featured_teams = Rails.cache.fetch(Team::FEATURED_TEAMS_CACHE_KEY, :expires_in => 4.hours) do
11-
Team.featured.sort_by(&:relevancy).reject { |team| team.jobs.count == 0 }.reverse!
12-
end
10+
#@featured_teams = Rails.cache.fetch(Team::FEATURED_TEAMS_CACHE_KEY, expires_in: 4.hours) do
11+
@featured_teams = Team.featured.sort_by(&:relevancy).reject do |team|
12+
team.jobs.count == 0
13+
end.reverse!
14+
#end
1315
@teams = []
1416
end
1517

@@ -62,6 +64,7 @@ def show
6264
format.json do
6365
options = { :expires_in => 5.minutes }
6466
options[:force] = true if !show_params[:refresh].blank?
67+
Team
6568
response = Rails.cache.fetch(['v1', 'team', show_params[:id], :json], options) do
6669
begin
6770
@team = team_from_params(slug: show_params[:slug], id: show_params[:id])
@@ -309,6 +312,7 @@ def page_based_on_rank(rank)
309312
end
310313

311314
def job_public_ids
315+
Opportunity
312316
Rails.cache.fetch('all-jobs-public-ids', :expires_in => 1.hour) { Opportunity.select(:public_id).group('team_id, created_at, public_id').map(&:public_id) }
313317
end
314318

‎app/jobs/process_team_job.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ def perform(process_type, team_id)
77
team = Team.find(team_id)
88
case process_type
99
when 'recalculate'
10-
if team.team_members.size <= 0
10+
if team.members.size <= 0
1111
team.destroy
1212
Redis.current.zrem(Team::LEADERBOARD_KEY, team.id.to_s)
1313
else
1414
team.recalculate!
15-
if team.team_members.size < 3
15+
if team.members.size < 3
1616
Redis.current.zrem(Team::LEADERBOARD_KEY, team.id.to_s)
1717
else
1818
Redis.current.zadd(Team::LEADERBOARD_KEY, team.score.to_f, team.id.to_s)
@@ -24,4 +24,4 @@ def perform(process_type, team_id)
2424
end
2525
end
2626
end
27-
end
27+
end

‎app/jobs/team_migrator_batch_job.rb

-14
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.