Skip to content

Commit 118c24b

Browse files
seurosjust3ws
authored andcommitted
💀 mongodb
1 parent 0fb8fba commit 118c24b

32 files changed

+507
-151
lines changed

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ gem 'sitemap_generator'
126126
gem 'tweet-button'
127127
gem 'local_time'
128128

129+
gem 'elasticsearch-model'
130+
gem 'elasticsearch-rails'
131+
129132
# DROP BEFORE RAILS 4
130133
# Mongo
131134
gem 'mongoid'
@@ -182,6 +185,7 @@ group :test do
182185
gem 'timecop'
183186
gem 'vcr'
184187
gem 'webmock', '<1.16'
188+
gem 'stripe-ruby-mock', git: 'https://github.com/rebelidealist/stripe-ruby-mock', branch: 'live-tests'
185189
end
186190

187191
gem 'airbrake'

Gemfile.lock

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ GEM
106106
rack (>= 0.9.0)
107107
binding_of_caller (0.7.2)
108108
debug_inspector (>= 0.0.1)
109+
blankslate (3.1.3)
109110
bson (1.10.2)
110111
bson_ext (1.10.2)
111112
bson (~> 1.10.2)
@@ -176,6 +177,7 @@ GEM
176177
httparty (~> 0.10)
177178
json
178179
curb (0.8.6)
180+
dante (0.2.0)
179181
database_cleaner (1.3.0)
180182
debug_inspector (0.0.2)
181183
debugger-linecache (1.2.0)
@@ -195,6 +197,19 @@ GEM
195197
execjs
196198
eco-source (1.1.0.rc.1)
197199
ejs (1.1.1)
200+
elasticsearch (1.0.4)
201+
elasticsearch-api (= 1.0.4)
202+
elasticsearch-transport (= 1.0.4)
203+
elasticsearch-api (1.0.4)
204+
multi_json
205+
elasticsearch-model (0.1.4)
206+
activesupport (> 3)
207+
elasticsearch (> 0.4)
208+
hashie
209+
elasticsearch-rails (0.1.4)
210+
elasticsearch-transport (1.0.4)
211+
faraday
212+
multi_json
198213
em-http-request (1.1.2)
199214
addressable (>= 2.3.4)
200215
cookiejar
@@ -330,6 +345,11 @@ GEM
330345
jbuilder (2.1.3)
331346
activesupport (>= 3.0.0, < 5)
332347
multi_json (~> 1.2)
348+
jimson-temp (0.9.5)
349+
blankslate (>= 3.1.2)
350+
multi_json (~> 1.0)
351+
rack (~> 1.4)
352+
rest-client (~> 1.0)
333353
journey (1.0.4)
334354
jquery-rails (2.0.3)
335355
railties (>= 3.1.0, < 5.0)
@@ -758,6 +778,8 @@ DEPENDENCIES
758778
createsend
759779
database_cleaner
760780
dotenv-rails
781+
elasticsearch-model
782+
elasticsearch-rails
761783
ember-rails!
762784
fabrication-rails
763785
faraday (~> 0.8.1)
@@ -844,6 +866,7 @@ DEPENDENCIES
844866
spring-commands-rspec
845867
squeel (= 1.0.1)
846868
stripe!
869+
stripe-ruby-mock!
847870
strong_parameters
848871
syntax
849872
timecop

app/jobs/refresh_user_job.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ def perform(user_id, full=false)
77

88
user = User.find(user_id)
99

10-
if user.github_id
11-
user.destroy_github_cache
12-
end
13-
1410
return if !full && user.last_refresh_at > 3.days.ago
1511

1612
begin
@@ -21,7 +17,6 @@ def perform(user_id, full=false)
2117
user.calculate_score!
2218
ensure
2319
user.touch(:last_refresh_at)
24-
user.destroy_github_cache
2520
end
2621
end
2722
end

app/jobs/team_migrator_batch_job.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#TODO DELETE ME
2+
class TeamMigratorBatchJob
3+
include Sidekiq::Worker
4+
5+
def perform
6+
Team.each do |team|
7+
TeamMigratorJob.perform_async(team.id.to_s)
8+
end
9+
end
10+
end

app/jobs/team_migrator_job.rb

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
#TODO DELETE ME
2+
class TeamMigratorJob
3+
include Sidekiq::Worker
4+
5+
sidekiq_options backtrace: true
6+
7+
def perform(id)
8+
team = Team.find(id)
9+
if pgteam = find_or_initialize_team(id, team)
10+
extract_account(pgteam, team)
11+
12+
extract_locations(pgteam, team)
13+
extract_links(pgteam, team)
14+
add_members(pgteam)
15+
add_jobs(pgteam)
16+
convert_followers(pgteam)
17+
add_pending_requests(pgteam, team)
18+
end
19+
end
20+
21+
22+
private
23+
24+
def find_or_initialize_team(id, team)
25+
begin
26+
PgTeam.find_or_initialize_by_mongo_id(id) do |pgteam|
27+
pgteam.name = team.name
28+
pgteam.slug = team.slug
29+
pgteam.created_at = team.created_at
30+
pgteam.updated_at = team.updated_at
31+
pgteam.website = team.website
32+
pgteam.about = team.about
33+
pgteam.total = team.total
34+
pgteam.size = team.size
35+
pgteam.mean = team.mean
36+
pgteam.median = team.median
37+
pgteam.score = team.score
38+
pgteam.twitter = team.twitter
39+
pgteam.facebook = team.facebook
40+
pgteam.premium = team.premium
41+
pgteam.analytics = team.analytics
42+
pgteam.valid_jobs = team.valid_jobs
43+
pgteam.hide_from_featured = team.hide_from_featured
44+
pgteam.preview_code = team.preview_code
45+
pgteam.youtube_url = team.youtube_url
46+
pgteam.github = team.github
47+
pgteam.highlight_tags = team.highlight_tags
48+
pgteam.branding = team.branding
49+
pgteam.headline = team.headline
50+
pgteam.big_quote = team.big_quote
51+
pgteam.big_image = team.big_image
52+
pgteam.featured_banner_image = team.featured_banner_image
53+
pgteam.benefit_name_1 = team.benefit_name_1
54+
pgteam.benefit_description_1 = team.benefit_description_1
55+
pgteam.benefit_name_2 = team.benefit_name_2
56+
pgteam.benefit_description_2 = team.benefit_description_2
57+
pgteam.benefit_name_3 = team.benefit_name_3
58+
pgteam.benefit_description_3 = team.benefit_description_3
59+
pgteam.reason_name_1 = team.reason_name_1
60+
pgteam.reason_description_1 = team.reason_description_1
61+
pgteam.reason_name_2 = team.reason_name_2
62+
pgteam.reason_description_2 = team.reason_description_2
63+
pgteam.reason_name_3 = team.reason_name_3
64+
pgteam.reason_description_3 = team.reason_description_3
65+
pgteam.why_work_image = team.why_work_image
66+
pgteam.organization_way = team.organization_way
67+
pgteam.organization_way_name = team.organization_way_name
68+
pgteam.organization_way_photo = team.organization_way_photo
69+
pgteam.office_photos = team.office_photos
70+
pgteam.upcoming_events = team.upcoming_events
71+
pgteam.featured_links_title = team.featured_links_title
72+
pgteam.blog_feed = team.blog_feed
73+
pgteam.our_challenge = team.our_challenge
74+
pgteam.your_impact = team.your_impact
75+
pgteam.interview_steps = team.interview_steps
76+
pgteam.hiring_tagline = team.hiring_tagline
77+
pgteam.link_to_careers_page = team.link_to_careers_page
78+
# pgteam.avatar = team.avatar
79+
pgteam.achievement_count = team.achievement_count
80+
pgteam.endorsement_count = team.endorsement_count
81+
pgteam.invited_emails = team.invited_emails
82+
pgteam.pending_join_requests = team.pending_join_requests
83+
pgteam.upgraded_at = team.upgraded_at
84+
pgteam.paid_job_posts = team.paid_job_posts
85+
pgteam.monthly_subscription = team.monthly_subscription
86+
pgteam.stack_list = team.stack_list
87+
pgteam.number_of_jobs_to_show = team.number_of_jobs_to_show
88+
pgteam.location = team.location
89+
pgteam.country_id = team.country_id
90+
pgteam.github_organization_name = team.github_organization_name
91+
pgteam.save!
92+
93+
end
94+
rescue ActiveRecord::RecordInvalid
95+
false
96+
end
97+
end
98+
99+
def extract_account(pgteam, team)
100+
return unless account = team.account
101+
return if pgteam.account
102+
begin
103+
pgaccount = pgteam.build_account(
104+
stripe_card_token: account.stripe_card_token,
105+
stripe_customer_token: account.stripe_customer_token,
106+
admin_id: account.admin_id
107+
)
108+
pgaccount.plans << Plan.where(id: account.plan_ids)
109+
pgaccount.save!
110+
rescue ActiveRecord::RecordInvalid => e
111+
# @just3ws, uncomment the following line and get all ID of the corrupted accounts
112+
# raise e
113+
false
114+
end
115+
116+
end
117+
118+
def extract_locations(pgteam, team)
119+
locations = team.team_locations
120+
return unless locations.any?
121+
return if pgteam.locations.any?
122+
locations.each do |location|
123+
pgteam.locations.create! name: location.name,
124+
description: location.description,
125+
address: location.address,
126+
city: location.city,
127+
state_code: location.state_code,
128+
country: location.country
129+
130+
end
131+
end
132+
133+
def extract_links(pgteam, team)
134+
links = team.featured_links
135+
return if links.empty?
136+
return if pgteam.links.any?
137+
links.each do |link|
138+
pgteam.links.create! name: link.name,
139+
url: link.url
140+
end
141+
end
142+
143+
def add_members(pgteam)
144+
users = User.where(team_document_id: pgteam.mongo_id)
145+
users.each do |user|
146+
pgteam.members.create! user: user, state: 'active'
147+
end
148+
users.update_all(team_id: pgteam.id)
149+
end
150+
151+
def add_jobs(pgteam)
152+
Opportunity.where(team_document_id: pgteam.mongo_id).update_all(team_id: pgteam.id)
153+
end
154+
155+
def convert_followers(pgteam)
156+
FollowedTeam.where(team_document_id: pgteam.mongo_id).update_all(team_id: pgteam.id)
157+
end
158+
159+
def add_pending_requests(pgteam, team)
160+
pending_team_members = team.pending_team_members
161+
return if pending_team_members.empty?
162+
pending_team_members.each do |pending_team_member|
163+
user = User.find pending_team_member.user_id
164+
pgteam.members.create user: user,
165+
created_at: pending_team_member.created_at,
166+
updated_at: pending_team_member.updated_at
167+
end
168+
end
169+
end

app/models/concerns/team_migration.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module TeamMigration
2+
extend ActiveSupport::Concern
3+
4+
included do
5+
scope :zombies, -> { where(state: 'zombie') }
6+
end
7+
8+
module ClassMethods
9+
10+
def the_walking_deads
11+
active_teams_ids = Teams::Member.pluck(:team_id).uniq
12+
where('id not in (?)', active_teams_ids)
13+
end
14+
15+
def mark_the_walking_deads!
16+
the_walking_deads.update_all(state: 'zombie')
17+
end
18+
19+
def kill_zombies!
20+
zombies.destroy_all
21+
end
22+
23+
end
24+
end

app/models/concerns/team_search.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module TeamSearch
2+
extend ActiveSupport::Concern
3+
included do
4+
include Elasticsearch::Model
5+
6+
#TODO
7+
end
8+
end

app/models/followed_team.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
class FollowedTeam < ActiveRecord::Base
2+
belongs_to :team, class_name: 'PgTeam'
3+
belongs_to :user
24
end
35

46
# == Schema Information
5-
# Schema version: 20140728214411
67
#
78
# Table name: followed_teams
89
#
910
# id :integer not null, primary key
1011
# user_id :integer
1112
# team_document_id :string(255)
12-
# created_at :datetime default(2014-02-20 22:39:11 UTC)
13+
# created_at :datetime default(2012-03-12 21:01:09 UTC)
14+
# team_id :integer
1315
#

0 commit comments

Comments
 (0)