Improved caching, moved to websockets.
This commit is contained in:
parent
66137dcf7b
commit
43d99d266e
9 changed files with 144 additions and 89 deletions
|
@ -27,6 +27,18 @@ class Index extends App.Controller
|
|||
|
||||
# get data / in case also ticket data for split
|
||||
fetch: (params) ->
|
||||
|
||||
# use cache
|
||||
if window.LastRefresh[ 'ticket_create_attributes' ] && !params.ticket_id && !params.article_id
|
||||
|
||||
# get edit form attributes
|
||||
@edit_form = window.LastRefresh[ 'ticket_create_attributes' ].edit_form
|
||||
|
||||
# load user collection
|
||||
@loadCollection( type: 'User', data: window.LastRefresh[ 'ticket_create_attributes' ].users )
|
||||
|
||||
@render()
|
||||
else
|
||||
App.Com.ajax(
|
||||
id: 'ticket_create',
|
||||
type: 'GET',
|
||||
|
@ -38,21 +50,17 @@ class Index extends App.Controller
|
|||
processData: true,
|
||||
success: (data, status, xhr) =>
|
||||
|
||||
# cache request
|
||||
window.LastRefresh[ 'ticket_create_attributes' ] = data
|
||||
|
||||
# get edit form attributes
|
||||
@edit_form = data.edit_form
|
||||
|
||||
# load user collection
|
||||
@loadCollection( type: 'User', data: data.users )
|
||||
|
||||
# render page
|
||||
if !params.ticket_id && !params.article_id
|
||||
@render()
|
||||
else
|
||||
|
||||
# load user collection
|
||||
@loadCollection( type: 'User', data: data.users )
|
||||
|
||||
# load ticket collection
|
||||
if data.ticket && data.articles
|
||||
@loadCollection( type: 'Ticket', data: [data.ticket] )
|
||||
|
||||
# load article collections
|
||||
|
|
|
@ -86,29 +86,10 @@ class TicketOverviewsController < ApplicationController
|
|||
# GET /ticket_create/1
|
||||
def ticket_create
|
||||
|
||||
# get related users
|
||||
users = {}
|
||||
|
||||
ticket_group_ids = []
|
||||
Group.where( :active => true ).each { |group|
|
||||
ticket_group_ids.push group.id
|
||||
}
|
||||
ticket_owner_ids = []
|
||||
Ticket.agents.each { |user|
|
||||
ticket_owner_ids.push user.id
|
||||
if !users[user.id]
|
||||
users[user.id] = user_data_full(user.id)
|
||||
end
|
||||
}
|
||||
|
||||
ticket_state_ids = []
|
||||
Ticket::State.where( :active => true ).each { |state|
|
||||
ticket_state_ids.push state.id
|
||||
}
|
||||
ticket_priority_ids = []
|
||||
Ticket::Priority.where( :active => true ).each { |priority|
|
||||
ticket_priority_ids.push priority.id
|
||||
}
|
||||
# get attributes
|
||||
(users, ticket_owner_ids, ticket_group_ids, ticket_state_ids, ticket_priority_ids) = Ticket.create_attributes(
|
||||
:current_user_id => current_user.id,
|
||||
)
|
||||
|
||||
# split data
|
||||
ticket = nil
|
||||
|
|
|
@ -8,18 +8,15 @@ class ApplicationModel < ActiveRecord::Base
|
|||
if o.respond_to?('cache_delete') then o.cache_delete end
|
||||
end
|
||||
def cache_delete
|
||||
# puts 'cache_delete', self.id
|
||||
key = self.class.to_s + '::' + self.id.to_s
|
||||
Rails.cache.delete( key.to_s )
|
||||
Cache.delete( key.to_s )
|
||||
end
|
||||
def self.cache_set(data_id, data)
|
||||
# puts 'cache_set', data_id
|
||||
key = self.to_s + '::' + data_id.to_s
|
||||
Rails.cache.write( key.to_s, data )
|
||||
Cache.write( key.to_s, data )
|
||||
end
|
||||
def self.cache_get(data_id)
|
||||
# puts 'cache_get', data_id
|
||||
key = self.to_s + '::' + data_id.to_s
|
||||
Rails.cache.read( key.to_s )
|
||||
Cache.get( key.to_s )
|
||||
end
|
||||
end
|
||||
|
|
|
@ -240,6 +240,43 @@ class Ticket < ActiveRecord::Base
|
|||
|
||||
end
|
||||
|
||||
|
||||
# Ticket.create_attributes(
|
||||
# :current_user_id => 123,
|
||||
# )
|
||||
def self.create_attributes (data)
|
||||
|
||||
# get groups
|
||||
ticket_group_ids = []
|
||||
Group.where( :active => true ).each { |group|
|
||||
ticket_group_ids.push group.id
|
||||
}
|
||||
|
||||
# get related users
|
||||
users = {}
|
||||
ticket_owner_ids = []
|
||||
Ticket.agents.each { |user|
|
||||
ticket_owner_ids.push user.id
|
||||
if !users[user.id]
|
||||
users[user.id] = User.user_data_full(user.id)
|
||||
end
|
||||
}
|
||||
|
||||
# get states
|
||||
ticket_state_ids = []
|
||||
Ticket::State.where( :active => true ).each { |state|
|
||||
ticket_state_ids.push state.id
|
||||
}
|
||||
|
||||
# get priorities
|
||||
ticket_priority_ids = []
|
||||
Ticket::Priority.where( :active => true ).each { |priority|
|
||||
ticket_priority_ids.push priority.id
|
||||
}
|
||||
|
||||
return users, ticket_owner_ids, ticket_group_ids, ticket_state_ids, ticket_priority_ids
|
||||
end
|
||||
|
||||
private
|
||||
def number_generate
|
||||
Ticket.new.number_adapter = Setting.get('ticket_number')
|
||||
|
|
|
@ -158,7 +158,8 @@ Your #{config.product_name} Team
|
|||
|
||||
def self.find_fulldata(user_id)
|
||||
|
||||
return cache_get(user_id) if cache_get(user_id)
|
||||
cache = self.cache_get(user_id)
|
||||
return cache if cache
|
||||
|
||||
# get user
|
||||
user = User.find(user_id)
|
||||
|
@ -180,29 +181,31 @@ Your #{config.product_name} Team
|
|||
# set roles
|
||||
roles = []
|
||||
user.roles.select('id, name').where( :active => true ).each { |role|
|
||||
roles.push role
|
||||
roles.push role.attributes
|
||||
}
|
||||
data['roles'] = roles
|
||||
data['role_ids'] = user.role_ids
|
||||
|
||||
groups = []
|
||||
user.groups.select('id, name').where( :active => true ).each { |group|
|
||||
groups.push group
|
||||
groups.push group.attributes
|
||||
}
|
||||
data['groups'] = groups
|
||||
data['group_ids'] = user.group_ids
|
||||
|
||||
organization = user.organization
|
||||
data['organization'] = organization
|
||||
if organization
|
||||
data['organization'] = organization.attributes
|
||||
end
|
||||
|
||||
organizations = []
|
||||
user.organizations.select('id, name').where( :active => true ).each { |organization|
|
||||
organizations.push organization
|
||||
organizations.push organization.attributes
|
||||
}
|
||||
data['organizations'] = organizations
|
||||
data['organization_ids'] = user.organization_ids
|
||||
|
||||
cache_set(user.id, data)
|
||||
self.cache_set(user.id, data)
|
||||
|
||||
return data
|
||||
end
|
||||
|
|
|
@ -16,6 +16,7 @@ require 'notification_factory'
|
|||
# load lib
|
||||
require 'gmaps'
|
||||
require 'rss'
|
||||
require 'cache'
|
||||
|
||||
require 'web_socket'
|
||||
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
# clear cache
|
||||
if Zammad::Application.config.cache_store[1] && File.directory?(Zammad::Application.config.cache_store[1])
|
||||
puts 'clear cache...'
|
||||
Rails.cache.clear
|
||||
end
|
||||
|
||||
# to get rails caching working, load models
|
||||
Dir.foreach("#{Rails.root}/app/models") do |model_name|
|
||||
require_dependency model_name unless model_name == '.' || model_name == '..' || model_name == '.gitkeep'
|
||||
end
|
14
lib/cache.rb
Normal file
14
lib/cache.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Cache
|
||||
def self.delete( key )
|
||||
puts 'Cache.delete' + key.to_s
|
||||
Rails.cache.delete( key.to_s )
|
||||
end
|
||||
def self.write( key, data )
|
||||
puts 'Cache.write: ' + key.to_s
|
||||
Rails.cache.write( key.to_s, data )
|
||||
end
|
||||
def self.get( key )
|
||||
puts 'Cache.get: ' + key.to_s
|
||||
Rails.cache.read( key.to_s )
|
||||
end
|
||||
end
|
|
@ -66,21 +66,23 @@ module Session
|
|||
next if !user_session[:id]
|
||||
user = User.find( user_session[:id] )
|
||||
|
||||
# overviews
|
||||
result = Ticket.overview(
|
||||
# overview meta data
|
||||
overview = Ticket.overview(
|
||||
:current_user_id => user.id,
|
||||
)
|
||||
if state_client_ids[client_id][:overview] != result
|
||||
state_client_ids[client_id][:overview] = result
|
||||
if state_client_ids[client_id][:overview] != overview
|
||||
state_client_ids[client_id][:overview] = overview
|
||||
|
||||
# send update to browser
|
||||
Session.transaction( client_id, {
|
||||
:action => 'load',
|
||||
:data => result,
|
||||
:data => overview,
|
||||
:event => 'navupdate_ticket_overview',
|
||||
})
|
||||
end
|
||||
|
||||
# ticket overview lists
|
||||
# list = Ticket.overview_list()
|
||||
|
||||
# recent viewed
|
||||
recent_viewed = History.recent_viewed(user)
|
||||
if state_client_ids[client_id][:recent_viewed] != recent_viewed
|
||||
|
@ -91,7 +93,6 @@ module Session
|
|||
|
||||
# send update to browser
|
||||
Session.transaction( client_id, {
|
||||
:action => 'load',
|
||||
:data => recent_viewed,
|
||||
:event => 'update_recent_viewed',
|
||||
})
|
||||
|
@ -110,6 +111,23 @@ module Session
|
|||
:collection => 'activity_stream',
|
||||
:data => activity_stream,
|
||||
})
|
||||
|
||||
# ticket create
|
||||
ticket_create_attributes = Ticket.create_attributes(
|
||||
:current_user_id => user.id,
|
||||
)
|
||||
if state_client_ids[client_id][:ticket_create_attributes] != ticket_create_attributes
|
||||
state_client_ids[client_id][:ticket_create_attributes] = ticket_create_attributes
|
||||
|
||||
# send update to browser
|
||||
Session.transaction( client_id, {
|
||||
:data => ticket_create_attributes,
|
||||
:collection => 'ticket_create_attributes',
|
||||
})
|
||||
end
|
||||
|
||||
# system settings
|
||||
|
||||
end
|
||||
|
||||
# rss view
|
||||
|
|
Loading…
Reference in a new issue