Improved caching.

This commit is contained in:
Martin Edenhofer 2012-07-29 20:55:51 +02:00
parent d3b5cf7586
commit fb910d03a3
9 changed files with 30 additions and 36 deletions

View file

@ -18,11 +18,11 @@ class ApplicationController < ActionController::Base
headers['Access-Control-Allow-Headers'] = 'Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control'
headers['Access-Control-Allow-Credentials'] = 'true'
end
# If this is a preflight OPTIONS request, then short-circuit the
# request, return only the necessary headers and return an empty
# text/plain.
def cors_preflight_check
if request.method == 'OPTIONS'
headers['Access-Control-Allow-Origin'] = '*'
@ -34,8 +34,7 @@ class ApplicationController < ActionController::Base
return false
end
end
private
# execute events
@ -81,7 +80,7 @@ class ApplicationController < ActionController::Base
current_user_set(userdata)
return true
end
# return auth not ok
render(
:json => {
@ -141,7 +140,7 @@ class ApplicationController < ActionController::Base
:name => object.class.name
)
end
History.create(
:o_id => object.id,
:history_type_id => history_type.id,
@ -160,8 +159,4 @@ class ApplicationController < ActionController::Base
return config
end
def user_data_full (user_id)
user = User.user_data_full(user_id)
end
end

View file

@ -75,7 +75,7 @@ class SessionsController < ApplicationController
# Save the user ID in the session so it can be used in
# subsequent requests
user = user_data_full( user_id )
user = User.user_data_full( user_id )
# auto population of default collections
default_collection = default_collections()

View file

@ -48,13 +48,13 @@ class TicketOverviewsController < ApplicationController
overview[:tickets].each {|ticket|
tickets.push ticket.attributes
if !users[ ticket.owner_id ]
users[ ticket.owner_id ] = user_data_full( ticket.owner_id )
users[ ticket.owner_id ] = User.user_data_full( ticket.owner_id )
end
if !users[ ticket.customer_id ]
users[ ticket.customer_id ] = user_data_full( ticket.customer_id )
users[ ticket.customer_id ] = User.user_data_full( ticket.customer_id )
end
if !users[ ticket.created_by_id ]
users[ ticket.created_by_id ] = user_data_full( ticket.created_by_id )
users[ ticket.created_by_id ] = User.user_data_full( ticket.created_by_id )
end
}
@ -64,7 +64,7 @@ class TicketOverviewsController < ApplicationController
bulk_owners.each { |user|
bulk_owner_ids.push user.id
if !users[ user.id ]
users[ user.id ] = user_data_full( user.id )
users[ user.id ] = User.user_data_full( user.id )
end
}
@ -100,20 +100,20 @@ class TicketOverviewsController < ApplicationController
# get related users
users = {}
if !users[ticket.owner_id]
users[ticket.owner_id] = user_data_full(ticket.owner_id)
users[ticket.owner_id] = User.user_data_full(ticket.owner_id)
end
if !users[ticket.customer_id]
users[ticket.customer_id] = user_data_full(ticket.customer_id)
users[ticket.customer_id] = User.user_data_full(ticket.customer_id)
end
if !users[ticket.created_by_id]
users[ticket.created_by_id] = user_data_full(ticket.created_by_id)
users[ticket.created_by_id] = User.user_data_full(ticket.created_by_id)
end
owner_ids = []
ticket.agent_of_group.each { |user|
owner_ids.push user.id
if !users[user.id]
users[user.id] = user_data_full(user.id)
users[user.id] = User.user_data_full(user.id)
end
}
@ -127,7 +127,7 @@ class TicketOverviewsController < ApplicationController
# load users
if !users[article.created_by_id]
users[article.created_by_id] = user_data_full(article.created_by_id)
users[article.created_by_id] = User.user_data_full(article.created_by_id)
end
end
@ -160,20 +160,20 @@ class TicketOverviewsController < ApplicationController
# get related users
users = {}
if !users[ticket.owner_id]
users[ticket.owner_id] = user_data_full(ticket.owner_id)
users[ticket.owner_id] = User.user_data_full(ticket.owner_id)
end
if !users[ticket.customer_id]
users[ticket.customer_id] = user_data_full(ticket.customer_id)
users[ticket.customer_id] = User.user_data_full(ticket.customer_id)
end
if !users[ticket.created_by_id]
users[ticket.created_by_id] = user_data_full(ticket.created_by_id)
users[ticket.created_by_id] = User.user_data_full(ticket.created_by_id)
end
owner_ids = []
ticket.agent_of_group.each { |user|
owner_ids.push user.id
if !users[user.id]
users[user.id] = user_data_full(user.id)
users[user.id] = User.user_data_full(user.id)
end
}
@ -192,7 +192,7 @@ class TicketOverviewsController < ApplicationController
# load users
if !users[article.created_by_id]
users[article.created_by_id] = user_data_full(article.created_by_id)
users[article.created_by_id] = User.user_data_full(article.created_by_id)
end
}
@ -349,7 +349,7 @@ class TicketOverviewsController < ApplicationController
# get related users
users = {}
history.each do |item|
users[ item['created_by_id'] ] = user_data_full( item['created_by_id'] )
users[ item['created_by_id'] ] = User.user_data_full( item['created_by_id'] )
if item['history_object'] == 'Ticket::Article'
item['type'] = 'Article ' + item['type'].to_s
else

View file

@ -1,5 +1,5 @@
class Authorization < ApplicationModel
belongs_to :user
belongs_to :user, :after_add => :cache_update, :after_remove => :cache_update
validates_presence_of :user_id, :uid, :provider
validates_uniqueness_of :uid, :scope => :provider

View file

@ -1,5 +1,5 @@
class Group < ApplicationModel
has_and_belongs_to_many :users
has_and_belongs_to_many :users, :after_add => :cache_update, :after_remove => :cache_update
after_create :cache_delete
after_update :cache_delete
after_destroy :cache_delete

View file

@ -1,5 +1,5 @@
class Role < ApplicationModel
has_and_belongs_to_many :users
has_and_belongs_to_many :users, :after_add => :cache_update, :after_remove => :cache_update
after_create :cache_delete
after_update :cache_delete
after_destroy :cache_delete

View file

@ -1,4 +1,4 @@
class Translation < ApplicationModel
class Translation < ActiveRecord::Base
before_create :set_initial
private

View file

@ -1,5 +0,0 @@
# clear cache
if Zammad::Application.config.cache_store[1] && File.directory?(Zammad::Application.config.cache_store[1])
puts 'clear cache...'
Rails.cache.clear
end

View file

@ -5,7 +5,7 @@ module Cache
end
def self.write( key, data, params = {} )
if !params[:expires_in]
params[:expires_in] = 48.hours
params[:expires_in] = 24.hours
end
puts 'Cache.write: ' + key.to_s
Rails.cache.write( key.to_s, data, params)
@ -14,4 +14,8 @@ module Cache
puts 'Cache.get: ' + key.to_s
Rails.cache.read( key.to_s )
end
def self.clear
puts 'Cache.clear...'
Rails.cache.clear
end
end