Skip to content

Instantly share code, notes, and snippets.

View Ross-Hunter's full-sized avatar

Ross-Hunter Ross-Hunter

View GitHub Profile
@Ross-Hunter
Ross-Hunter / gist:e45f24d4d68ddec94496
Created May 15, 2015 20:24
Some architecture stuff in a fake language
# ActiveRecord
## Domain
### /bucket-form
def post params
bucket = params['bucket']
machine = params['machine']
machine.save

#Automate your life!

##Foreman is a thing for running multiple processes https://github.com/ddollar/foreman

You define your processes using a Procfile

something like...

web: bundle exec rails s

### Before
1)
EXPLAIN ANALYZE SELECT "cards".* FROM "cards" WHERE "cards"."expansion_id" = 130 ORDER BY name;
-------------------------------------------------------------------------------
Sort (cost=1367.55..1368.17 rows=248 width=348) (actual time=12.634..12.654 rows=249 loops=1)
Sort Key: name
Sort Method: quicksort Memory: 148kB
-> Seq Scan on cards (cost=0.00..1357.69 rows=248 width=348) (actual time=0.195..9.857 rows=249 loops=1)
Filter: (expansion_id = 130)
Rows Removed by Filter: 22526
class AddIndexesToTransactions < ActiveRecord::Migration
def change
add_index :transactions, :card_id
add_index :transactions, :trade_id
end
end
##Class
class User
has_many :memberships
has_many :groups, through: :memberships
end
class Membership
belongs_to :user
belongs_to :group
##Class
class User
has_and_belongs_to_many :groups
end
class Group
has_and_belongs_to_many :groups
end
##Class
class User
has_one :profile
has_many :avatars, through: :profile
end
class Profile
belongs_to :user
has_many :avatars
##Class
class User
has_one :profile
has_one :avatar, through: :profile
end
class Profile
belongs_to :user
has_one :avatar
##Class
class User
has_one :profile # inverse_of :profile not necessary in 4.1+
end
class Profile
belongs_to :user # inverse_of :user not necessary in 4.1+
end
##Class
class User
belongs_to :group, inverse_of: :member
end
class Group
# inverse_of because we are adding options to the relationship that prevent
# automatic guessing of the inverse
has_many :members, class_name: "User", inverse_of: :user