Changed strategy of caching.

This commit is contained in:
Martin Edenhofer 2012-07-29 22:25:31 +02:00
parent b4bb6ae059
commit cac0c86d9e
2 changed files with 46 additions and 18 deletions

View file

@ -40,21 +40,23 @@ class TicketOverviewsController < ApplicationController
:view_mode => params[:view_mode], :view_mode => params[:view_mode],
:current_user_id => current_user.id, :current_user_id => current_user.id,
:start_page => params[:start_page], :start_page => params[:start_page],
:array => true,
) )
# get related users # get related users
users = {} users = {}
tickets = [] tickets = []
overview[:tickets].each {|ticket| overview[:tickets].each {|ticket|
tickets.push ticket.attributes data = Ticket.full_data(ticket.id)
if !users[ ticket.owner_id ] tickets.push data
users[ ticket.owner_id ] = User.user_data_full( ticket.owner_id ) if !users[ data['owner_id'] ]
users[ data['owner_id'] ] = User.user_data_full( data['owner_id'] )
end end
if !users[ ticket.customer_id ] if !users[ data['customer_id'] ]
users[ ticket.customer_id ] = User.user_data_full( ticket.customer_id ) users[ data['customer_id'] ] = User.user_data_full( data['customer_id'] )
end end
if !users[ ticket.created_by_id ] if !users[ data['created_by_id'] ]
users[ ticket.created_by_id ] = User.user_data_full( ticket.created_by_id ) users[ data['created_by_id'] ] = User.user_data_full( data['created_by_id'] )
end end
} }

View file

@ -1,15 +1,19 @@
class Ticket < ActiveRecord::Base class Ticket < ApplicationModel
before_create :number_generate, :check_defaults before_create :number_generate, :check_defaults
before_destroy :destroy_dependencies before_destroy :destroy_dependencies
belongs_to :group 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_state, :class_name => 'Ticket::State'
belongs_to :ticket_priority, :class_name => 'Ticket::Priority' belongs_to :ticket_priority, :class_name => 'Ticket::Priority'
belongs_to :owner, :class_name => 'User' belongs_to :owner, :class_name => 'User'
belongs_to :customer, :class_name => 'User' belongs_to :customer, :class_name => 'User'
belongs_to :created_by, :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 @@number_adapter = nil
def number_adapter def number_adapter
@ -207,7 +211,7 @@ class Ticket < ActiveRecord::Base
where( :group_id => group_ids ). where( :group_id => group_ids ).
where( overview_selected.condition ). where( overview_selected.condition ).
order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s ). 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 ). tickets_count = Ticket.where( :group_id => group_ids ).
where( overview_selected.condition ). where( overview_selected.condition ).
@ -240,6 +244,15 @@ class Ticket < ActiveRecord::Base
end 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( # Ticket.create_attributes(
# :current_user_id => 123, # :current_user_id => 123,
@ -308,21 +321,30 @@ class Ticket < ActiveRecord::Base
class Number class Number
end end
class Flag < ActiveRecord::Base class Flag < ApplicationModel
end end
class Priority < ActiveRecord::Base class Priority < ApplicationModel
self.table_name = 'ticket_priorities' self.table_name = 'ticket_priorities'
after_create :cache_delete
after_update :cache_delete
after_destroy :cache_delete
end end
class StateType < ActiveRecord::Base class StateType < ApplicationModel
after_create :cache_delete
after_update :cache_delete
after_destroy :cache_delete
end end
class State < ActiveRecord::Base class State < ApplicationModel
belongs_to :ticket_state_type, :class_name => 'Ticket::StateType' belongs_to :ticket_state_type, :class_name => 'Ticket::StateType'
after_create :cache_delete
after_update :cache_delete
after_destroy :cache_delete
end end
class Article < ActiveRecord::Base class Article < ApplicationModel
before_create :fillup before_create :fillup
after_create :attachment_check, :communicate after_create :attachment_check, :communicate
belongs_to :ticket belongs_to :ticket
@ -330,6 +352,10 @@ class Ticket < ActiveRecord::Base
belongs_to :ticket_article_sender, :class_name => 'Ticket::Article::Sender' belongs_to :ticket_article_sender, :class_name => 'Ticket::Article::Sender'
belongs_to :created_by, :class_name => 'User' belongs_to :created_by, :class_name => 'User'
after_create :cache_delete
after_update :cache_delete
after_destroy :cache_delete
private private
def fillup def fillup
@ -462,13 +488,13 @@ class Ticket < ActiveRecord::Base
end end
end end
class Flag < ActiveRecord::Base class Flag < ApplicationModel
end end
class Sender < ActiveRecord::Base class Sender < ApplicationModel
end end
class Type < ActiveRecord::Base class Type < ApplicationModel
end end
end end