Improved memory usage.

This commit is contained in:
Martin Edenhofer 2016-09-27 23:15:27 +02:00
parent 6b81b791ed
commit 0d377d40ab

View file

@ -40,15 +40,15 @@ class _ajaxSingleton
cache: false
async: true
current_request: {}
queue_list: []
queue_running: false
currentRequest: {}
queueList: []
queueRunning: false
count: 0
constructor: (@args) ->
# run queue
@_run()
@runNextInQueue()
# bindings
$(document).bind('ajaxSend', =>
@ -80,8 +80,8 @@ class _ajaxSingleton
# show error message
new App.ControllerModal(
head: 'StatusCode: ' + status
contentInline: '<pre>' + App.Utils.htmlEscape(detail) + '</pre>'
head: "StatusCode: #{status}"
contentInline: "<pre>#{App.Utils.htmlEscape(detail)}</pre>"
buttonClose: true
buttonSubmit: false
)
@ -93,55 +93,66 @@ class _ajaxSingleton
# execute call with id, clear old call first if exists
if params['id']
@abort(params['id'])
@current_request[ params['id'] ] = $.ajax( data )
@addCurrentRequest(params['id'], data)
return params['id']
# generate a uniq rand id
params['id'] = 'rand-' + new Date().getTime() + '-' + Math.floor( Math.random() * 99999 )
params['id'] = "rand-#{new Date().getTime()}-#{Math.floor(Math.random() * 99999)}"
# queue request
if params['queue']
@queue_list.push data
if !@queue_running
@_run()
@queueList.push data
if !@queueRunning
@runNextInQueue()
# execute request
else
@current_request[ params['id'] ] = $.ajax(data)
@addCurrentRequest(params['id'], data)
params['id']
addCurrentRequest: (id, data, queueRunning) =>
data.complete = =>
if queueRunning
@queueRunning = false
@removeCurrentRequest(id)
if queueRunning
@runNextInQueue()
@currentRequest[id] = $.ajax(data)
return if data.async is true
@removeCurrentRequest(id)
removeCurrentRequest: (id) =>
@currentRequest[id] = undefined
delete @currentRequest[id]
abort: (id) =>
# abort current_request
if @current_request[ id ]
@current_request[ id ].abort()
delete @current_request[ id ]
# abort currentRequest
if @currentRequest[id]
@currentRequest[id].abort()
@currentRequest[id] = undefined
delete @currentRequest[id]
# remove from queue list
@queue_list = _.filter(
@queue_list
@queueList = _.filter(
@queueList
(item) ->
return item if item['id'] isnt id
return
)
abortAll: =>
return if !@current_request
abortedIds = []
for id, ajax of @current_request
for id, ajax of @currentRequest
@abort(id)
abortedIds.push id
abortedIds
_run: =>
if @queue_list && @queue_list[0]
@queue_running = true
request = @queue_list.shift()
request.complete = =>
@queue_running = false
@_run()
@current_request[ request['id'] ] = $.ajax( request )
runNextInQueue: =>
if @queueList && @queueList[0]
@queueRunning = true
data = @queueList.shift()
@addCurrentRequest(params['id'], data, true)
_show_spinner: =>
@count++