mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-03 06:21:49 +01:00
Added some database optimizations, mostly in the form of indices on commonly queried columns
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@396 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
ead9a4cfe9
commit
d8ec265ca4
6 changed files with 48 additions and 11 deletions
|
|
@ -16,7 +16,6 @@ class ApplicationController < ActionController::Base
|
|||
layout 'standard'
|
||||
|
||||
before_filter :set_session_expiration
|
||||
before_filter :get_current_user
|
||||
prepend_before_filter :login_required
|
||||
|
||||
after_filter :set_charset
|
||||
|
|
@ -64,12 +63,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
private
|
||||
|
||||
def get_current_user
|
||||
@user = User.find(session['user_id']) if session['user_id']
|
||||
@prefs = @user.prefs unless @user.nil?
|
||||
end
|
||||
|
||||
|
||||
def parse_date_per_user_prefs( s )
|
||||
return nil if s.blank?
|
||||
@user.prefs.tz.unadjust(Date.strptime(s, @user.prefs.date_format)).utc.to_date
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ class ContextController < ApplicationController
|
|||
# TODO: Temporarily doing this search manually until I can work out a way
|
||||
# to do the same thing using not_done_todos acts_as_todo_container method
|
||||
# Hides actions in hidden projects from context.
|
||||
@not_done_todos = @context.todos.find_in_state(:all, :active, :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC")
|
||||
@not_done_todos = @context.todos.find(:all, :conditions => ['todos.state = ?', 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => :project)
|
||||
@count = @not_done_todos.size
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
has_many :notes, :order => "created_at DESC", :dependent => :delete_all
|
||||
has_one :preference
|
||||
has_one :preference, :dependent => :destroy
|
||||
|
||||
attr_protected :is_admin
|
||||
|
||||
|
|
|
|||
23
tracks/db/migrate/022_add_indices.rb
Normal file
23
tracks/db/migrate/022_add_indices.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
class AddIndices < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_index :todos, [:user_id, :state]
|
||||
add_index :todos, [:user_id, :project_id]
|
||||
add_index :todos, [:project_id]
|
||||
add_index :todos, [:context_id]
|
||||
add_index :todos, [:user_id, :context_id]
|
||||
add_index :preferences, :user_id
|
||||
add_index :projects, :user_id
|
||||
add_index :contexts, :user_id
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_index :contexts, :user_id
|
||||
remove_index :projects, :user_id
|
||||
remove_index :preferences, :user_id
|
||||
remove_index :todos, [:user_id, :context_id]
|
||||
remove_index :todos, [:project_id]
|
||||
remove_index :todos, [:context_id]
|
||||
remove_index :todos, [:user_id, :project_id]
|
||||
remove_index :todos, [:user_id, :state]
|
||||
end
|
||||
end
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
# migrations feature of ActiveRecord to incrementally modify your database, and
|
||||
# then regenerate this schema definition.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 21) do
|
||||
ActiveRecord::Schema.define(:version => 22) do
|
||||
|
||||
create_table "contexts", :force => true do |t|
|
||||
t.column "name", :string, :default => "", :null => false
|
||||
|
|
@ -11,6 +11,8 @@ ActiveRecord::Schema.define(:version => 21) do
|
|||
t.column "user_id", :integer, :default => 0, :null => false
|
||||
end
|
||||
|
||||
add_index "contexts", ["user_id"], :name => "index_contexts_on_user_id"
|
||||
|
||||
create_table "notes", :force => true do |t|
|
||||
t.column "user_id", :integer, :default => 0, :null => false
|
||||
t.column "project_id", :integer, :default => 0, :null => false
|
||||
|
|
@ -54,6 +56,8 @@ ActiveRecord::Schema.define(:version => 21) do
|
|||
t.column "time_zone", :string, :default => "London", :null => false
|
||||
end
|
||||
|
||||
add_index "preferences", ["user_id"], :name => "index_preferences_on_user_id"
|
||||
|
||||
create_table "projects", :force => true do |t|
|
||||
t.column "name", :string, :default => "", :null => false
|
||||
t.column "position", :integer, :default => 0, :null => false
|
||||
|
|
@ -62,6 +66,8 @@ ActiveRecord::Schema.define(:version => 21) do
|
|||
t.column "state", :string, :limit => 20, :default => "active", :null => false
|
||||
end
|
||||
|
||||
add_index "projects", ["user_id"], :name => "index_projects_on_user_id"
|
||||
|
||||
create_table "sessions", :force => true do |t|
|
||||
t.column "session_id", :string
|
||||
t.column "data", :text
|
||||
|
|
@ -83,6 +89,12 @@ ActiveRecord::Schema.define(:version => 21) do
|
|||
t.column "state", :string, :limit => 20, :default => "immediate", :null => false
|
||||
end
|
||||
|
||||
add_index "todos", ["user_id", "state"], :name => "index_todos_on_user_id_and_state"
|
||||
add_index "todos", ["user_id", "project_id"], :name => "index_todos_on_user_id_and_project_id"
|
||||
add_index "todos", ["project_id"], :name => "index_todos_on_project_id"
|
||||
add_index "todos", ["context_id"], :name => "index_todos_on_context_id"
|
||||
add_index "todos", ["user_id", "context_id"], :name => "index_todos_on_user_id_and_context_id"
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.column "login", :string, :limit => 80
|
||||
t.column "password", :string, :limit => 40
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ module LoginSystem
|
|||
return true
|
||||
end
|
||||
|
||||
if session['user_id'] and authorize?(User.find(session['user_id']))
|
||||
if session['user_id'] and authorize?(get_current_user)
|
||||
return true
|
||||
end
|
||||
|
||||
|
|
@ -64,6 +64,14 @@ module LoginSystem
|
|||
access_denied
|
||||
return false
|
||||
end
|
||||
|
||||
def get_current_user
|
||||
if @user.nil? && session['user_id']
|
||||
@user = User.find session['user_id'], :include => :preference
|
||||
end
|
||||
@prefs = @user.prefs unless @user.nil?
|
||||
@user
|
||||
end
|
||||
|
||||
# overwrite if you want to have special behavior in case the user is not authorized
|
||||
# to access the current operation.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue