From 7ce34e9d296615721ad956b1d71c12667e973a75 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Wed, 17 Jun 2015 13:03:07 +0200 Subject: [PATCH] AutoCommit Mit Jun 17 13:03:07 CEST 2015 --- Gemfile | 2 +- app/models/neuigkeit.rb | 9 +++++---- config/initializers/query_trace.rb | 1 + .../20150617105704_add_index_for_neuigkeiten.rb | 12 ++++++++++++ 4 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 config/initializers/query_trace.rb create mode 100644 db/migrate/20150617105704_add_index_for_neuigkeiten.rb diff --git a/Gemfile b/Gemfile index bf54489..e923aac 100755 --- a/Gemfile +++ b/Gemfile @@ -22,7 +22,7 @@ group :assets do gem 'therubyracer', :platforms => :ruby gem 'uglifier', '>= 1.0.3' end - +gem 'active_record_query_trace' gem 'jquery-rails' diff --git a/app/models/neuigkeit.rb b/app/models/neuigkeit.rb index 32a1dc4..3d2004d 100755 --- a/app/models/neuigkeit.rb +++ b/app/models/neuigkeit.rb @@ -21,7 +21,7 @@ class Neuigkeit < ActiveRecord::Base has_many :nlinks, :dependent=> :destroy has_one :meeting has_many :attachments, :as=>:parent - + has_one :title_pic, :class_name=>"Attachment", :as=>:parent, :conditions=>["attachments.flag_titlepic =?", true] validates :rubrik, :presence=>true @@ -29,7 +29,7 @@ class Neuigkeit < ActiveRecord::Base translates :title,:text, :versioning=>{:gem=>:paper_trail, :options=>{:fallbacks_for_empty_translations => true}} mount_uploader :picture, PictureUploader - default_scope order(:cache_order) + default_scope order(:cache_order).includes(:calentries).includes(:title_pic) scope :recent, -> { published.limit(10)} scope :unpublished, -> {where("datum > ? OR datum IS NULL", Time.now)} scope :published_scope, ->{where("datum <= ? AND datum IS NOT NULL", Time.now)} @@ -66,8 +66,9 @@ class Neuigkeit < ActiveRecord::Base if self.has_meeting? return self.meeting.meetingtyp.picture else - unless self.attachments.where(flag_titlepic: true).first.nil? - return self.attachments.where(flag_titlepic: true).first.datei + unless self.title_pic.nil? + # return self.attachments.where(flag_titlepic: true).first.datei + return self.title_pic.datei else return self.picture end diff --git a/config/initializers/query_trace.rb b/config/initializers/query_trace.rb new file mode 100644 index 0000000..a2c486b --- /dev/null +++ b/config/initializers/query_trace.rb @@ -0,0 +1 @@ +ActiveRecordQueryTrace.enabled=true diff --git a/db/migrate/20150617105704_add_index_for_neuigkeiten.rb b/db/migrate/20150617105704_add_index_for_neuigkeiten.rb new file mode 100644 index 0000000..1a58c39 --- /dev/null +++ b/db/migrate/20150617105704_add_index_for_neuigkeiten.rb @@ -0,0 +1,12 @@ +class AddIndexForNeuigkeiten < ActiveRecord::Migration + def up + add_index :neuigkeiten, :rubrik_id + add_index :calentries, [:object_type, :object_id] + add_index :attachments, [:parent_type, :parent_id] + add_index :attachments, [:flag_titlepic, :parent_type, :parent_id] + add_index :neuigkeit_translations, :neuigkeit_id + end + + def down + end +end