Refactoring: Migrated LDAP and Excachange statistics to new sum/total structure for clearer results and better performance.

This commit is contained in:
Thorsten Eckel 2018-01-08 16:30:09 +01:00
parent f0cf7c3605
commit e37328d201
12 changed files with 42 additions and 69 deletions

View file

@ -131,13 +131,12 @@ class Form extends App.Controller
if _.isEmpty(job)
@lastImport.html('')
return
countDone = job.result.created + job.result.updated + job.result.unchanged + job.result.skipped + job.result.failed
if !job.result.roles
job.result.roles = {}
for role_id, statistic of job.result.role_ids
role = App.Role.find(role_id)
job.result.roles[role.displayName()] = statistic
el = $(App.view('integration/exchange_last_import')(job: job, countDone: countDone))
el = $(App.view('integration/exchange_last_import')(job: job))
@lastImport.html(el)
activeDryRun: =>
@ -540,34 +539,26 @@ class ConnectionWizard extends App.WizardModal
@showAlert('js-error', (job.result.error || job.result.info))
return
total = 0
if job.result && _.keys(job.result).length > 0
@$('.js-preprogress').addClass('hide')
@$('.js-analyzing').removeClass('hide')
analized = 0
total = job.result.sum
for action, sum of job.result
continue if action == 'folders'
continue if action == 'sum'
analized += sum
@$('.js-progress progress').attr('value', analized)
@$('.js-progress progress').attr('max', total)
@$('.js-progress progress').attr('value', job.result.sum)
@$('.js-progress progress').attr('max', job.result.total)
if job.finished_at
# reset initial state in case the back button is used
@$('.js-preprogress').removeClass('hide')
@$('.js-analyzing').addClass('hide')
@tryResult(job, total)
@tryResult(job)
else
@delay(@tryLoop, 4000)
)
tryResult: (job, total) =>
tryResult: (job) =>
@showSlide('js-try')
el = $(App.view('integration/exchange_summary')(job: job, countDone: total))
el = $(App.view('integration/exchange_summary')(job: job))
@el.find('.js-summary').html(el)
App.Config.set(

View file

@ -132,13 +132,12 @@ class Form extends App.Controller
if _.isEmpty(job)
@lastImport.html('')
return
countDone = job.result.created + job.result.updated + job.result.unchanged + job.result.skipped + job.result.failed
if !job.result.roles
job.result.roles = {}
for role_id, statistic of job.result.role_ids
role = App.Role.find(role_id)
job.result.roles[role.displayName()] = statistic
el = $(App.view('integration/ldap_last_import')(job: job, countDone: countDone))
el = $(App.view('integration/ldap_last_import')(job: job))
@lastImport.html(el)
activeDryRun: =>
@ -539,22 +538,12 @@ class ConnectionWizard extends App.WizardModal
@showAlert('js-error', (job.result.error || job.result.info))
return
if job.result && job.result.sum
if job.result && job.result.total
@$('.js-preprogress').addClass('hide')
@$('.js-analyzing').removeClass('hide')
total = 0
if job.result.created
total += job.result.created
if job.result.failed
total += job.result.failed
if job.result.skipped
total += job.result.skipped
if job.result.unchanged
total += job.result.unchanged
if job.result.updated
total += job.result.updated
@$('.js-progress progress').attr('value', total)
@$('.js-progress progress').attr('max', job.result.sum)
@$('.js-progress progress').attr('value', job.result.sum)
@$('.js-progress progress').attr('max', job.result.total)
if job.finished_at
# reset initial state in case the back button is used
@$('.js-preprogress').removeClass('hide')
@ -574,9 +563,8 @@ class ConnectionWizard extends App.WizardModal
for role_id, statistic of job.result.role_ids
role = App.Role.find(role_id)
job.result.roles[role.displayName()] = statistic
countDone = job.result.created + job.result.updated + job.result.unchanged + job.result.skipped
@showSlide('js-try')
el = $(App.view('integration/ldap_summary')(job: job, countDone: countDone))
el = $(App.view('integration/ldap_summary')(job: job))
@el.find('.js-summary').html(el)
App.Config.set(

View file

@ -20,18 +20,18 @@
<% if @job.result && @job.result.error: %>
<p><%- @Ttimestamp(@job.started_at) %></p>
<div class="alert alert--danger" role="alert"><%- @T('An error occurred: %s', @job.result.error) %></div>
<% else if !@countDone: %>
<% else if @job.result && !@job.result.sum: %>
<p><%- @Ttimestamp(@job.started_at) %> - <%- @T('Counting entries. This may take a while.') %></p>
<% else: %>
<p><%- @Ttimestamp(@job.started_at) %> - <%- @T('Running...') %></p>
<div class="flex">
<progress max="<%= @job.result.sum %>" value="<%= @countDone %>"></progress>
<progress max="<%= @job.result.total %>" value="<%= @job.result.sum %>"></progress>
</div>
<% end %>
<% end %>
<% if !_.isEmpty(@job.result) && @countDone: %>
<% if !_.isEmpty(@job.result) && @job.result.sum: %>
<ul>
<li><%- @T('%s user to %s user', 'Exchange', 'Zammad') %> (<%= @countDone %>/<%= @job.result.sum %>):
<li><%- @T('%s user to %s user', 'Exchange', 'Zammad') %> (<%= @job.result.sum %>/<%= @job.result.total %>):
<ul>
<li><%- @T('Users') %>: <%= @job.result.created %> <%- @T('created') %>, <%= @job.result.updated %> <%- @T('updated') %>, <%= @job.result.unchanged %> <%- @T('untouched') %>, <%= @job.result.skipped %> <%- @T('skipped') %>, <%= @job.result.failed %> <%- @T('failed') %>
</ul>

View file

@ -1,5 +1,5 @@
<ul>
<li><%- @T('%s user to %s user', 'Exchange', 'Zammad') %> (<%= @countDone %>):
<li><%- @T('%s user to %s user', 'Exchange', 'Zammad') %> (<%= @job.result.total %>):
<ul>
<li><%- @T('Users') %>: <%= @job.result.created %> <%- @T('created') %>, <%= @job.result.updated %> <%- @T('updated') %>, <%= @job.result.unchanged %> <%- @T('untouched') %>, <%= @job.result.skipped %> <%- @T('skipped') %>, <%= @job.result.failed %> <%- @T('failed') %>
</ul>

View file

@ -20,18 +20,18 @@
<% if @job.result && @job.result.error: %>
<p><%- @Ttimestamp(@job.started_at) %></p>
<div class="alert alert--danger" role="alert"><%- @T('An error occurred: %s', @job.result.error) %></div>
<% else if !@countDone: %>
<% else if !@job.result.sum: %>
<p><%- @Ttimestamp(@job.started_at) %> - <%- @T('Counting entries. This may take a while.') %></p>
<% else: %>
<p><%- @Ttimestamp(@job.started_at) %> - <%- @T('Running...') %></p>
<div class="flex">
<progress max="<%= @job.result.sum %>" value="<%= @countDone %>"></progress>
<progress max="<%= @job.result.total %>" value="<%= @job.result.sum %>"></progress>
</div>
<% end %>
<% end %>
<% if !_.isEmpty(@job.result) && @countDone: %>
<% if !_.isEmpty(@job.result) && @job.result.sum: %>
<ul>
<li><%- @T('%s user to %s user', 'LDAP', 'Zammad') %> (<%= @countDone %>/<%= @job.result.sum %>):
<li><%- @T('%s user to %s user', 'LDAP', 'Zammad') %> (<%= @job.result.sum %>/<%= @job.result.total %>):
<ul>
<li><%- @T('Users') %>: <%= @job.result.created %> <%- @T('created') %>, <%= @job.result.updated %> <%- @T('updated') %>, <%= @job.result.unchanged %> <%- @T('untouched') %>, <%= @job.result.skipped %> <%- @T('skipped') %>, <%= @job.result.failed %> <%- @T('failed') %>, <%= @job.result.deactivated %> <%- @T('deactivated') %>
</ul>

View file

@ -1,5 +1,5 @@
<ul>
<li><%- @T('%s user to %s user', 'LDAP', 'Zammad') %> (<%= @countDone %>):
<li><%- @T('%s user to %s user', 'LDAP', 'Zammad') %> (<%= @job.result.sum %>):
<ul>
<li><%- @T('Users') %>: <%= @job.result.created %> <%- @T('created') %>, <%= @job.result.updated %> <%- @T('updated') %>, <%= @job.result.unchanged %> <%- @T('untouched') %>, <%= @job.result.skipped %> <%- @T('skipped') %>, <%= @job.result.failed %> <%- @T('failed') %>, <%= @job.result.deactivated %> <%- @T('deactivated') %>
</ul>

View file

@ -9,7 +9,7 @@ class Sequencer
'Import::Exchange::FolderContacts::DryRunPayload',
'Exchange::Connection',
'Import::Exchange::FolderContacts::FolderIds',
'Import::Exchange::FolderContacts::Sum',
'Import::Exchange::FolderContacts::Total',
'Import::Common::ImportJob::Statistics::Update',
'Import::Common::ImportJob::Statistics::Store',
'Import::Exchange::FolderContacts::SubSequence',

View file

@ -13,7 +13,7 @@ class Sequencer
'Ldap::Config',
'Ldap::Connection',
'Import::Ldap::Users::UserRoles',
'Import::Ldap::Users::Sum',
'Import::Ldap::Users::Total',
'Import::Common::ImportJob::Statistics::Update',
'Import::Common::ImportJob::Statistics::Store',
'Import::Ldap::Users::SubSequence',

View file

@ -11,15 +11,11 @@ class Sequencer
def process
state.provide(:statistics_diff) do
# remove :sum since it's already set via
# the exchange item attribute
result = diff.except(:sum)
# build structure for a general diff
# and a folder specific sub structure
result.merge(
diff.merge(
folders: {
ews_folder_name => result
ews_folder_name => diff
}
)
end

View file

@ -3,8 +3,9 @@ class Sequencer
module Import
module Exchange
module FolderContacts
class Sum < Sequencer::Unit::Base
class Total < Sequencer::Unit::Base
include ::Sequencer::Unit::Exchange::Folders::Mixin::Folder
include ::Sequencer::Unit::Import::Common::Model::Statistics::Mixin::Common
uses :ews_folder_ids
provides :statistics_diff
@ -16,21 +17,22 @@ class Sequencer
private
def diff
result = {
sum: 0,
}
folder_sum_map.each do |display_path, sum|
result = empty_diff.merge(
folders: {},
)
result[display_path] = {
sum: sum
}
folder_total_map.each do |display_path, total|
result[:sum] += sum
result[:folders][display_path] = empty_diff.merge(
total: total
)
result[:total] += total
end
result
end
def folder_sum_map
def folder_total_map
ews_folder_ids.collect do |folder_id|
folder = ews_folder.find(folder_id)
display_path = ews_folder.display_path(folder)

View file

@ -13,11 +13,7 @@ class Sequencer
def process
state.provide(:statistics_diff) do
# remove :sum since it's already set via
# the outer count Unit
statistics = diff.except(:sum)
add_role_ids(statistics)
add_role_ids(diff)
end
end

View file

@ -5,7 +5,7 @@ class Sequencer
module Import
module Ldap
module Users
class Sum < Sequencer::Unit::Base
class Total < Sequencer::Unit::Base
include ::Sequencer::Unit::Import::Common::Model::Statistics::Mixin::EmptyDiff
uses :ldap_config, :ldap_connection, :dry_run
@ -13,14 +13,14 @@ class Sequencer
def process
state.provide(:statistics_diff) do
diff.merge(
sum: sum
total: total
)
end
end
private
def sum
def total
if !dry_run
result = Cache.get(cache_key)
end