Changed strategy of caching.
This commit is contained in:
parent
b4bb6ae059
commit
cac0c86d9e
2 changed files with 46 additions and 18 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue