Permalink
Browse files

Add Memberships indices and User#login index.

Eager load user SSH keys.
  • Loading branch information...
1 parent 3be8422 commit 25c68f546778a272227c65b7be626aa786a1e85e @nbibler nbibler committed Apr 4, 2011
@@ -2,7 +2,7 @@ class UsersController < ApplicationController
def index
@project = Project.find(params[:project_id])
- @users = @project.users
+ @users = @project.users.includes(:ssh_keys)
respond_to do |format|
format.yaml { render :text => @users.collect { |u| u.keymaster_data }.to_yaml }
@@ -11,7 +11,7 @@ def index
def show
@parent = params.has_key?(:project_id) ? Project.find(params[:project_id]).users : User
- @user = @parent.find_by_login(params[:id]) || raise(ActiveRecord::RecordNotFound)
+ @user = @parent.where(:login => params[:id]).includes(:ssh_keys).first || raise(ActiveRecord::RecordNotFound)
respond_to do |format|
format.yaml { render :text => @user.keymaster_data.to_yaml }
@@ -0,0 +1,11 @@
+class AddIndicesToMemberships < ActiveRecord::Migration
+ def self.up
+ add_index :memberships, :project_id
+ add_index :memberships, :user_id
+ end
+
+ def self.down
+ remove_index :memberships, :user_id
+ remove_index :memberships, :project_id
+ end
+end
@@ -0,0 +1,9 @@
+class AddLoginIndexToUsers < ActiveRecord::Migration
+ def self.up
+ add_index :users, :login, :unique => true
+ end
+
+ def self.down
+ remove_index :users, :login
+ end
+end
View
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110404013217) do
+ActiveRecord::Schema.define(:version => 20110404015102) do
create_table "memberships", :force => true do |t|
t.integer "project_id"
@@ -19,6 +19,9 @@
t.datetime "updated_at"
end
+ add_index "memberships", ["project_id"], :name => "index_memberships_on_project_id"
+ add_index "memberships", ["user_id"], :name => "index_memberships_on_user_id"
+
create_table "projects", :force => true do |t|
t.string "name"
t.datetime "created_at"
@@ -57,4 +60,6 @@
t.datetime "updated_at"
end
+ add_index "users", ["login"], :name => "index_users_on_login", :unique => true
+
end

0 comments on commit 25c68f5

Please sign in to comment.