Improved caching, moved to websockets.
This commit is contained in:
parent
66137dcf7b
commit
43d99d266e
9 changed files with 144 additions and 89 deletions
|
@ -27,49 +27,57 @@ class Index extends App.Controller
|
||||||
|
|
||||||
# get data / in case also ticket data for split
|
# get data / in case also ticket data for split
|
||||||
fetch: (params) ->
|
fetch: (params) ->
|
||||||
App.Com.ajax(
|
|
||||||
id: 'ticket_create',
|
|
||||||
type: 'GET',
|
|
||||||
url: '/ticket_create',
|
|
||||||
data: {
|
|
||||||
ticket_id: params.ticket_id,
|
|
||||||
article_id: params.article_id,
|
|
||||||
},
|
|
||||||
processData: true,
|
|
||||||
success: (data, status, xhr) =>
|
|
||||||
|
|
||||||
# get edit form attributes
|
|
||||||
@edit_form = data.edit_form
|
|
||||||
|
|
||||||
# load user collection
|
# use cache
|
||||||
@loadCollection( type: 'User', data: data.users )
|
if window.LastRefresh[ 'ticket_create_attributes' ] && !params.ticket_id && !params.article_id
|
||||||
|
|
||||||
# render page
|
# get edit form attributes
|
||||||
if !params.ticket_id && !params.article_id
|
@edit_form = window.LastRefresh[ 'ticket_create_attributes' ].edit_form
|
||||||
@render()
|
|
||||||
else
|
# load user collection
|
||||||
|
@loadCollection( type: 'User', data: window.LastRefresh[ 'ticket_create_attributes' ].users )
|
||||||
|
|
||||||
|
@render()
|
||||||
|
else
|
||||||
|
App.Com.ajax(
|
||||||
|
id: 'ticket_create',
|
||||||
|
type: 'GET',
|
||||||
|
url: '/ticket_create',
|
||||||
|
data: {
|
||||||
|
ticket_id: params.ticket_id,
|
||||||
|
article_id: params.article_id,
|
||||||
|
},
|
||||||
|
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
|
# load user collection
|
||||||
@loadCollection( type: 'User', data: data.users )
|
@loadCollection( type: 'User', data: data.users )
|
||||||
|
|
||||||
# load ticket collection
|
# load ticket collection
|
||||||
@loadCollection( type: 'Ticket', data: [data.ticket] )
|
if data.ticket && data.articles
|
||||||
|
@loadCollection( type: 'Ticket', data: [data.ticket] )
|
||||||
# load article collections
|
|
||||||
@loadCollection( type: 'TicketArticle', data: data.articles || [] )
|
# load article collections
|
||||||
|
@loadCollection( type: 'TicketArticle', data: data.articles || [] )
|
||||||
# render page
|
|
||||||
t = App.Ticket.find(params.ticket_id).attributes()
|
# render page
|
||||||
a = App.TicketArticle.find(params.article_id)
|
t = App.Ticket.find(params.ticket_id).attributes()
|
||||||
|
a = App.TicketArticle.find(params.article_id)
|
||||||
# reset owner
|
|
||||||
t.owner_id = 0
|
# reset owner
|
||||||
t.customer_id_autocompletion = a.from
|
t.owner_id = 0
|
||||||
t.subject = a.subject || t.title
|
t.customer_id_autocompletion = a.from
|
||||||
t.body = a.body
|
t.subject = a.subject || t.title
|
||||||
@log '11111', t
|
t.body = a.body
|
||||||
|
@log '11111', t
|
||||||
@render( options: t )
|
@render( options: t )
|
||||||
)
|
)
|
||||||
|
|
||||||
render: (template = {}) ->
|
render: (template = {}) ->
|
||||||
|
|
||||||
|
|
|
@ -86,29 +86,10 @@ class TicketOverviewsController < ApplicationController
|
||||||
# GET /ticket_create/1
|
# GET /ticket_create/1
|
||||||
def ticket_create
|
def ticket_create
|
||||||
|
|
||||||
# get related users
|
# get attributes
|
||||||
users = {}
|
(users, ticket_owner_ids, ticket_group_ids, ticket_state_ids, ticket_priority_ids) = Ticket.create_attributes(
|
||||||
|
:current_user_id => current_user.id,
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
# split data
|
# split data
|
||||||
ticket = nil
|
ticket = nil
|
||||||
|
|
|
@ -8,18 +8,15 @@ class ApplicationModel < ActiveRecord::Base
|
||||||
if o.respond_to?('cache_delete') then o.cache_delete end
|
if o.respond_to?('cache_delete') then o.cache_delete end
|
||||||
end
|
end
|
||||||
def cache_delete
|
def cache_delete
|
||||||
# puts 'cache_delete', self.id
|
|
||||||
key = self.class.to_s + '::' + self.id.to_s
|
key = self.class.to_s + '::' + self.id.to_s
|
||||||
Rails.cache.delete( key.to_s )
|
Cache.delete( key.to_s )
|
||||||
end
|
end
|
||||||
def self.cache_set(data_id, data)
|
def self.cache_set(data_id, data)
|
||||||
# puts 'cache_set', data_id
|
|
||||||
key = self.to_s + '::' + data_id.to_s
|
key = self.to_s + '::' + data_id.to_s
|
||||||
Rails.cache.write( key.to_s, data )
|
Cache.write( key.to_s, data )
|
||||||
end
|
end
|
||||||
def self.cache_get(data_id)
|
def self.cache_get(data_id)
|
||||||
# puts 'cache_get', data_id
|
|
||||||
key = self.to_s + '::' + data_id.to_s
|
key = self.to_s + '::' + data_id.to_s
|
||||||
Rails.cache.read( key.to_s )
|
Cache.get( key.to_s )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -240,6 +240,43 @@ class Ticket < ActiveRecord::Base
|
||||||
|
|
||||||
end
|
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
|
private
|
||||||
def number_generate
|
def number_generate
|
||||||
Ticket.new.number_adapter = Setting.get('ticket_number')
|
Ticket.new.number_adapter = Setting.get('ticket_number')
|
||||||
|
|
|
@ -31,24 +31,24 @@ class User < ApplicationModel
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.authenticate( username, password )
|
def self.authenticate( username, password )
|
||||||
|
|
||||||
# do not authenticate with nothing
|
# do not authenticate with nothing
|
||||||
return if !username || username == ''
|
return if !username || username == ''
|
||||||
return if !password || password == ''
|
return if !password || password == ''
|
||||||
|
|
||||||
# try to find user based on login
|
# try to find user based on login
|
||||||
user = User.where( :login => username, :active => true ).first
|
user = User.where( :login => username, :active => true ).first
|
||||||
|
|
||||||
# try second lookup with email
|
# try second lookup with email
|
||||||
if !user
|
if !user
|
||||||
user = User.where( :email => username, :active => true ).first
|
user = User.where( :email => username, :active => true ).first
|
||||||
end
|
end
|
||||||
|
|
||||||
# no user found
|
# no user found
|
||||||
if !user
|
if !user
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# auth ok
|
# auth ok
|
||||||
if user.password == password
|
if user.password == password
|
||||||
return user
|
return user
|
||||||
|
@ -158,7 +158,8 @@ Your #{config.product_name} Team
|
||||||
|
|
||||||
def self.find_fulldata(user_id)
|
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
|
# get user
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
|
@ -180,29 +181,31 @@ Your #{config.product_name} Team
|
||||||
# set roles
|
# set roles
|
||||||
roles = []
|
roles = []
|
||||||
user.roles.select('id, name').where( :active => true ).each { |role|
|
user.roles.select('id, name').where( :active => true ).each { |role|
|
||||||
roles.push role
|
roles.push role.attributes
|
||||||
}
|
}
|
||||||
data['roles'] = roles
|
data['roles'] = roles
|
||||||
data['role_ids'] = user.role_ids
|
data['role_ids'] = user.role_ids
|
||||||
|
|
||||||
groups = []
|
groups = []
|
||||||
user.groups.select('id, name').where( :active => true ).each { |group|
|
user.groups.select('id, name').where( :active => true ).each { |group|
|
||||||
groups.push group
|
groups.push group.attributes
|
||||||
}
|
}
|
||||||
data['groups'] = groups
|
data['groups'] = groups
|
||||||
data['group_ids'] = user.group_ids
|
data['group_ids'] = user.group_ids
|
||||||
|
|
||||||
organization = user.organization
|
organization = user.organization
|
||||||
data['organization'] = organization
|
if organization
|
||||||
|
data['organization'] = organization.attributes
|
||||||
|
end
|
||||||
|
|
||||||
organizations = []
|
organizations = []
|
||||||
user.organizations.select('id, name').where( :active => true ).each { |organization|
|
user.organizations.select('id, name').where( :active => true ).each { |organization|
|
||||||
organizations.push organization
|
organizations.push organization.attributes
|
||||||
}
|
}
|
||||||
data['organizations'] = organizations
|
data['organizations'] = organizations
|
||||||
data['organization_ids'] = user.organization_ids
|
data['organization_ids'] = user.organization_ids
|
||||||
|
|
||||||
cache_set(user.id, data)
|
self.cache_set(user.id, data)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,6 +16,7 @@ require 'notification_factory'
|
||||||
# load lib
|
# load lib
|
||||||
require 'gmaps'
|
require 'gmaps'
|
||||||
require 'rss'
|
require 'rss'
|
||||||
|
require 'cache'
|
||||||
|
|
||||||
require 'web_socket'
|
require 'web_socket'
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
# clear cache
|
# clear cache
|
||||||
if Zammad::Application.config.cache_store[1] && File.directory?(Zammad::Application.config.cache_store[1])
|
if Zammad::Application.config.cache_store[1] && File.directory?(Zammad::Application.config.cache_store[1])
|
||||||
|
puts 'clear cache...'
|
||||||
Rails.cache.clear
|
Rails.cache.clear
|
||||||
end
|
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]
|
next if !user_session[:id]
|
||||||
user = User.find( user_session[:id] )
|
user = User.find( user_session[:id] )
|
||||||
|
|
||||||
# overviews
|
# overview meta data
|
||||||
result = Ticket.overview(
|
overview = Ticket.overview(
|
||||||
:current_user_id => user.id,
|
:current_user_id => user.id,
|
||||||
)
|
)
|
||||||
if state_client_ids[client_id][:overview] != result
|
if state_client_ids[client_id][:overview] != overview
|
||||||
state_client_ids[client_id][:overview] = result
|
state_client_ids[client_id][:overview] = overview
|
||||||
|
|
||||||
# send update to browser
|
# send update to browser
|
||||||
Session.transaction( client_id, {
|
Session.transaction( client_id, {
|
||||||
:action => 'load',
|
:data => overview,
|
||||||
:data => result,
|
|
||||||
:event => 'navupdate_ticket_overview',
|
:event => 'navupdate_ticket_overview',
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# ticket overview lists
|
||||||
|
# list = Ticket.overview_list()
|
||||||
|
|
||||||
# recent viewed
|
# recent viewed
|
||||||
recent_viewed = History.recent_viewed(user)
|
recent_viewed = History.recent_viewed(user)
|
||||||
if state_client_ids[client_id][:recent_viewed] != recent_viewed
|
if state_client_ids[client_id][:recent_viewed] != recent_viewed
|
||||||
|
@ -91,7 +93,6 @@ module Session
|
||||||
|
|
||||||
# send update to browser
|
# send update to browser
|
||||||
Session.transaction( client_id, {
|
Session.transaction( client_id, {
|
||||||
:action => 'load',
|
|
||||||
:data => recent_viewed,
|
:data => recent_viewed,
|
||||||
:event => 'update_recent_viewed',
|
:event => 'update_recent_viewed',
|
||||||
})
|
})
|
||||||
|
@ -110,6 +111,23 @@ module Session
|
||||||
:collection => 'activity_stream',
|
:collection => 'activity_stream',
|
||||||
:data => 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
|
end
|
||||||
|
|
||||||
# rss view
|
# rss view
|
||||||
|
|
Loading…
Reference in a new issue