Improved performance of ticket update.

This commit is contained in:
Martin Edenhofer 2014-09-23 07:37:43 +02:00
parent 24d9c523c4
commit ac44bd70d3
2 changed files with 52 additions and 52 deletions

View file

@ -576,26 +576,14 @@ class Edit extends App.Controller
@autosaveStart() @autosaveStart()
return return
ticket.article = article
ticket.save( ticket.save(
done: (r) => done: (r) =>
# reset form after save # reset form after save
if article App.TaskManager.update( @task_key, { 'state': {} })
article.save(
done: (r) =>
@ui.fetch( ticket.id, true )
# reset form after save @ui.fetch( ticket.id, true )
App.TaskManager.update( @task_key, { 'state': {} })
fail: (r) =>
@log 'error', 'update article', r
)
else
# reset form after save
App.TaskManager.update( @task_key, { 'state': {} })
@ui.fetch( ticket.id, true )
) )
reset: (e) => reset: (e) =>

View file

@ -22,7 +22,7 @@ class TicketsController < ApplicationController
# POST /api/v1/tickets # POST /api/v1/tickets
def create def create
@ticket = Ticket.new( Ticket.param_validation( params[:ticket] ) ) ticket = Ticket.new( Ticket.param_validation( params[:ticket] ) )
# check if article is given # check if article is given
if !params[:article] if !params[:article]
@ -31,8 +31,8 @@ class TicketsController < ApplicationController
end end
# create ticket # create ticket
if !@ticket.save if !ticket.save
render :json => @ticket.errors, :status => :unprocessable_entity render :json => ticket.errors, :status => :unprocessable_entity
return return
end end
@ -42,7 +42,7 @@ class TicketsController < ApplicationController
tags.each {|tag| tags.each {|tag|
Tag.tag_add( Tag.tag_add(
:object => 'Ticket', :object => 'Ticket',
:o_id => @ticket.id, :o_id => ticket.id,
:item => tag, :item => tag,
:created_by_id => current_user.id, :created_by_id => current_user.id,
) )
@ -51,57 +51,39 @@ class TicketsController < ApplicationController
# create article if given # create article if given
if params[:article] if params[:article]
form_id = params[:article][:form_id] article_create( ticket, params[:article] )
params[:article].delete(:form_id)
@article = Ticket::Article.new( Ticket::Article.param_validation( params[:article] ) )
@article.ticket_id = @ticket.id
# find attachments in upload cache
if form_id
@article.attachments = Store.list(
:object => 'UploadCache',
:o_id => form_id,
)
end
if !@article.save
render :json => @article.errors, :status => :unprocessable_entity
return
end
# remove attachments from upload cache
if form_id
Store.remove(
:object => 'UploadCache',
:o_id => form_id,
)
end
end end
render :json => @ticket, :status => :created render :json => ticket, :status => :created
end end
# PUT /api/v1/tickets/1 # PUT /api/v1/tickets/1
def update def update
@ticket = Ticket.find(params[:id]) ticket = Ticket.find(params[:id])
# permissin check # permissin check
return if !ticket_permission(@ticket) return if !ticket_permission(ticket)
if @ticket.update_attributes( Ticket.param_validation( params[:ticket] ) ) if ticket.update_attributes( Ticket.param_validation( params[:ticket] ) )
render :json => @ticket, :status => :ok
if params[:article]
article_create( ticket, params[:article] )
end
render :json => ticket, :status => :ok
else else
render :json => @ticket.errors, :status => :unprocessable_entity render :json => ticket.errors, :status => :unprocessable_entity
end end
end end
# DELETE /api/v1/tickets/1 # DELETE /api/v1/tickets/1
def destroy def destroy
@ticket = Ticket.find( params[:id] ) ticket = Ticket.find( params[:id] )
# permissin check # permissin check
return if !ticket_permission(@ticket) return if !ticket_permission(ticket)
@ticket.destroy ticket.destroy
head :ok head :ok
end end
@ -376,4 +358,34 @@ class TicketsController < ApplicationController
} }
end end
private
def article_create(ticket, params)
puts params.inspect
# create article if given
form_id = params[:form_id]
params.delete(:form_id)
article = Ticket::Article.new( Ticket::Article.param_validation( params ) )
article.ticket_id = ticket.id
# find attachments in upload cache
if form_id
article.attachments = Store.list(
:object => 'UploadCache',
:o_id => form_id,
)
end
if !article.save
render :json => article.errors, :status => :unprocessable_entity
return
end
# remove attachments from upload cache
if form_id
Store.remove(
:object => 'UploadCache',
:o_id => form_id,
)
end
end
end end