From cac0c86d9e0de1cc52bef0a69accdae6683b12ed Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 29 Jul 2012 22:25:31 +0200 Subject: [PATCH] Changed strategy of caching. --- .../ticket_overviews_controller.rb | 16 ++++--- app/models/ticket.rb | 48 ++++++++++++++----- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/app/controllers/ticket_overviews_controller.rb b/app/controllers/ticket_overviews_controller.rb index 6a8c59921..38a51d400 100644 --- a/app/controllers/ticket_overviews_controller.rb +++ b/app/controllers/ticket_overviews_controller.rb @@ -40,21 +40,23 @@ class TicketOverviewsController < ApplicationController :view_mode => params[:view_mode], :current_user_id => current_user.id, :start_page => params[:start_page], + :array => true, ) # get related users users = {} tickets = [] overview[:tickets].each {|ticket| - tickets.push ticket.attributes - if !users[ ticket.owner_id ] - users[ ticket.owner_id ] = User.user_data_full( ticket.owner_id ) + data = Ticket.full_data(ticket.id) + tickets.push data + if !users[ data['owner_id'] ] + users[ data['owner_id'] ] = User.user_data_full( data['owner_id'] ) end - if !users[ ticket.customer_id ] - users[ ticket.customer_id ] = User.user_data_full( ticket.customer_id ) + if !users[ data['customer_id'] ] + users[ data['customer_id'] ] = User.user_data_full( data['customer_id'] ) end - if !users[ ticket.created_by_id ] - users[ ticket.created_by_id ] = User.user_data_full( ticket.created_by_id ) + if !users[ data['created_by_id'] ] + users[ data['created_by_id'] ] = User.user_data_full( data['created_by_id'] ) end } diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 08e7cf175..5cde892be 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -1,15 +1,19 @@ -class Ticket < ActiveRecord::Base +class Ticket < ApplicationModel before_create :number_generate, :check_defaults before_destroy :destroy_dependencies belongs_to :group - has_many :articles + has_many :articles, :after_add => :cache_update, :after_remove => :cache_update belongs_to :ticket_state, :class_name => 'Ticket::State' belongs_to :ticket_priority, :class_name => 'Ticket::Priority' belongs_to :owner, :class_name => 'User' belongs_to :customer, :class_name => 'User' belongs_to :created_by, :class_name => 'User' + after_create :cache_delete + after_update :cache_delete + after_destroy :cache_delete + @@number_adapter = nil def number_adapter @@ -207,7 +211,7 @@ class Ticket < ActiveRecord::Base where( :group_id => group_ids ). where( overview_selected.condition ). order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s ). - limit( 4_000 ) + limit( 500 ) tickets_count = Ticket.where( :group_id => group_ids ). where( overview_selected.condition ). @@ -240,6 +244,15 @@ class Ticket < ActiveRecord::Base end +# data = Ticket.full_data(123) + def self.full_data(ticket_id) + cache = self.cache_get(ticket_id) + return cache if cache + + ticket = Ticket.find(ticket_id).attributes + self.cache_set( ticket_id, ticket ) + return ticket + end # Ticket.create_attributes( # :current_user_id => 123, @@ -308,21 +321,30 @@ class Ticket < ActiveRecord::Base class Number end - class Flag < ActiveRecord::Base + class Flag < ApplicationModel end - class Priority < ActiveRecord::Base + class Priority < ApplicationModel self.table_name = 'ticket_priorities' + after_create :cache_delete + after_update :cache_delete + after_destroy :cache_delete end - class StateType < ActiveRecord::Base + class StateType < ApplicationModel + after_create :cache_delete + after_update :cache_delete + after_destroy :cache_delete end - class State < ActiveRecord::Base + class State < ApplicationModel belongs_to :ticket_state_type, :class_name => 'Ticket::StateType' + after_create :cache_delete + after_update :cache_delete + after_destroy :cache_delete end - class Article < ActiveRecord::Base + class Article < ApplicationModel before_create :fillup after_create :attachment_check, :communicate belongs_to :ticket @@ -330,6 +352,10 @@ class Ticket < ActiveRecord::Base belongs_to :ticket_article_sender, :class_name => 'Ticket::Article::Sender' belongs_to :created_by, :class_name => 'User' + after_create :cache_delete + after_update :cache_delete + after_destroy :cache_delete + private def fillup @@ -462,13 +488,13 @@ class Ticket < ActiveRecord::Base end end - class Flag < ActiveRecord::Base + class Flag < ApplicationModel end - class Sender < ActiveRecord::Base + class Sender < ApplicationModel end - class Type < ActiveRecord::Base + class Type < ApplicationModel end end