From dfdfb15d43cb42e486939e79da5f6a1e944610ac Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 15 Oct 2016 03:30:14 +0200 Subject: [PATCH] Performance improvements (moved from interval to on demand). --- .../app/controllers/profile.coffee | 2 - .../javascripts/app/lib/app_post/ajax.coffee | 32 ++++++++--- .../app/lib/app_post/task_manager.coffee | 56 +++++++++++-------- test/browser/taskbar_task_test.rb | 2 +- 4 files changed, 59 insertions(+), 33 deletions(-) diff --git a/app/assets/javascripts/app/controllers/profile.coffee b/app/assets/javascripts/app/controllers/profile.coffee index 00e6bf92f..0358f12ce 100644 --- a/app/assets/javascripts/app/controllers/profile.coffee +++ b/app/assets/javascripts/app/controllers/profile.coffee @@ -22,7 +22,5 @@ class ProfileRouter extends App.ControllerPermanent App.Config.set('profile', ProfileRouter, 'Routes') App.Config.set('profile/:target', ProfileRouter, 'Routes') -App.Config.set('Profile', { controller: 'Profile', permission: ['user_preferences.*'] }, 'permanentTask') - App.Config.set('Profile', { prio: 1000, name: 'Profile', target: '#profile' }, 'NavBarProfile') App.Config.set('Profile', { prio: 1700, parent: '#current_user', name: 'Profile', target: '#profile', translate: true }, 'NavBarRight') diff --git a/app/assets/javascripts/app/lib/app_post/ajax.coffee b/app/assets/javascripts/app/lib/app_post/ajax.coffee index bbe82a457..9a9df5573 100644 --- a/app/assets/javascripts/app/lib/app_post/ajax.coffee +++ b/app/assets/javascripts/app/lib/app_post/ajax.coffee @@ -30,6 +30,16 @@ class App.Ajax _instance ?= new _ajaxSingleton _instance.abortAll() + @queue: -> + if _instance == undefined + _instance ?= new _ajaxSingleton + _instance.queue() + + @current: -> + if _instance == undefined + _instance ?= new _ajaxSingleton + _instance.current() + # The actual Singleton class class _ajaxSingleton defaults: @@ -91,24 +101,24 @@ class _ajaxSingleton data = $.extend({}, @defaults, params) # execute call with id, clear old call first if exists - if params['id'] - @abort(params['id']) - @addCurrentRequest(params['id'], data) - return params['id'] + if data['id'] + @abort(data['id']) + @addCurrentRequest(data['id'], data) + return data['id'] # generate a uniq rand id - params['id'] = "rand-#{new Date().getTime()}-#{Math.floor(Math.random() * 99999)}" + data['id'] = "rand-#{new Date().getTime()}-#{Math.floor(Math.random() * 99999)}" # queue request - if params['queue'] + if data['queue'] @queueList.push data if !@queueRunning @runNextInQueue() # execute request else - @addCurrentRequest(params['id'], data) - params['id'] + @addCurrentRequest(data['id'], data) + data['id'] addCurrentRequest: (id, data, queueRunning) => data.complete = => @@ -154,6 +164,12 @@ class _ajaxSingleton data = @queueList.shift() @addCurrentRequest(data['id'], data, true) + queue: => + @queueList + + current: => + @currentRequest + _show_spinner: => @count++ $('.spinner').show() diff --git a/app/assets/javascripts/app/lib/app_post/task_manager.coffee b/app/assets/javascripts/app/lib/app_post/task_manager.coffee index 3325dbf07..fb9331f66 100644 --- a/app/assets/javascripts/app/lib/app_post/task_manager.coffee +++ b/app/assets/javascripts/app/lib/app_post/task_manager.coffee @@ -83,9 +83,6 @@ class _taskManagerSingleton extends App.Controller @offlineModus = params.offlineModus @tasksInitial() - # send updates to server - App.Interval.set(@taskUpdateLoop, 3000, 'check_update_to_server_pending', 'task') - init: -> @domStore = {} @shownStore = {} @@ -220,7 +217,7 @@ class _taskManagerSingleton extends App.Controller # empty static content if task is shown if params.show - @el.find('#content').empty() + @$('#content').empty() # set all tasks to active false, only new/selected one to active if params.show @@ -279,7 +276,7 @@ class _taskManagerSingleton extends App.Controller if key isnt thisKey if @shownStore[key] isnt false @hide(key) - $('#content').addClass('hide') + @$('#content').addClass('hide') for key of @workers if key is thisKey @@ -292,18 +289,21 @@ class _taskManagerSingleton extends App.Controller domKey = @domID(key) domStoreItem = @domStore[domKey] - localEl = domStoreItem.el - if !@$("##{domKey}").get(0) && localEl - @el.append(localEl) - @$("##{domKey}").removeClass('hide').addClass('active') + if !@$("##{domKey}").get(0) && domStoreItem && domStoreItem.el + @el.append(domStoreItem.el) + @$("##{domKey}").removeClass('hide').addClass('active') + + if controller + + # set position of view + if domStoreItem.position + controller.setPosition(domStoreItem.position) + + else + @$("##{domKey}").removeClass('hide').addClass('active') if controller - # set position of view - position = @domStore[@domID(key)].position - if position - controller.setPosition(position) - # set controller state to active if controller.active && _.isFunction(controller.active) controller.active(true) @@ -319,17 +319,18 @@ class _taskManagerSingleton extends App.Controller controller = @workers[ key ] @shownStore[key] = false - if @$("##{@domID(key)}").get(0) + element = @$("##{@domID(key)}") + if element.get(0) domKey = @domID(key) domStoreItem = @domStore[domKey] if controller && _.isFunction(controller.currentPosition) position = controller.currentPosition() domStoreItem.position = position - @$("##{@domID(key)}").addClass('hide').removeClass('active') - domStoreItem.el = @$("##{@domID(key)}").detach() + element.addClass('hide').removeClass('active') + domStoreItem.el = element.detach() else - @$("##{@domID(key)}").addClass('hide').removeClass('active') + element.addClass('hide').removeClass('active') return false if !controller @@ -423,6 +424,7 @@ class _taskManagerSingleton extends App.Controller if localDomStore.el $('#app').append("
") $("#app ##{domKey}_trash").append(localDomStore.el).remove() + localDomStore.el = undefined localDomStore = undefined delete @domStore[@domID(key)] worker = @workers[key] @@ -430,8 +432,9 @@ class _taskManagerSingleton extends App.Controller worker = undefined delete @workers[key] try - @$("##{@domID(key)}").html('') - @$("##{@domID(key)}").remove() + element = @$("##{@domID(key)}") + element.html('') + element.remove() catch @log 'notice', "invalid key '#{key}'" @@ -484,6 +487,7 @@ class _taskManagerSingleton extends App.Controller taskUpdate: (task, mute = false) -> @log 'debug', 'UPDATE task', task, mute @tasksToUpdate[ task.key ] = 'toUpdate' + @taskUpdateTrigger() return if mute @touch(task.key) @@ -498,7 +502,12 @@ class _taskManagerSingleton extends App.Controller @title task.meta.title App.Event.trigger('taskUpdate', [task]) - App.Delay.set(delay, 20, "task-#{key}") + App.Delay.set(delay, 20, "task-#{key}", undefined) + + taskUpdateTrigger: => + + # send updates to server + App.Delay.set(@taskUpdateLoop, 2000, 'check_update_to_server_pending', 'task', true) taskUpdateLoop: => return if @offlineModus @@ -531,6 +540,7 @@ class _taskManagerSingleton extends App.Controller 800 undefined 'task' + true ) return @@ -544,7 +554,7 @@ class _taskManagerSingleton extends App.Controller tasksAutoCleanupDelay: => delay = => @tasksAutoCleanup() - App.Delay.set(delay, 10000, 'task-autocleanup') + App.Delay.set(delay, 12000, 'task-autocleanup', undefined, true) tasksAutoCleanup: => @@ -598,6 +608,7 @@ class _taskManagerSingleton extends App.Controller taskCount * 350 undefined 'task' + true ) # initial load of taskbar collection @@ -617,6 +628,7 @@ class _taskManagerSingleton extends App.Controller taskCount * 350 undefined 'task' + true ) App.Event.trigger 'taskbar:ready' diff --git a/test/browser/taskbar_task_test.rb b/test/browser/taskbar_task_test.rb index 32f8d1824..5702f4f4b 100644 --- a/test/browser/taskbar_task_test.rb +++ b/test/browser/taskbar_task_test.rb @@ -74,7 +74,7 @@ class TaskbarTaskTest < TestCase css: '.active .newTicket [data-name="body"]', value: 'OUTBOUND BODY TEST#1', ) - sleep 2 + sleep 3 logout() sleep 4