diff --git a/app/assets/javascripts/app/controllers/import_zendesk.coffee b/app/assets/javascripts/app/controllers/import_zendesk.coffee index a4856e235..1858adde1 100644 --- a/app/assets/javascripts/app/controllers/import_zendesk.coffee +++ b/app/assets/javascripts/app/controllers/import_zendesk.coffee @@ -10,6 +10,7 @@ class Index extends App.ControllerContent '.zendesk-api-token-error': 'apiTokenErrorMessage' '#zendesk-email': 'zendeskEmail' '#zendesk-api-token': 'zendeskApiToken' + '.js-ticket-count-info': 'ticketCountInfo' updateMigrationDisplayLoop: 0 events: @@ -172,6 +173,10 @@ class Index extends App.ControllerContent for key, item of data.data if item.done > item.total item.done = item.total + + if key == 'Ticket' && item.total >= 1000 + @ticketCountInfo.removeClass('hide') + element = @$('.js-' + key.toLowerCase() ) element.find('.js-done').text(item.done) element.find('.js-total').text(item.total) diff --git a/app/assets/javascripts/app/views/import/zendesk.jst.eco b/app/assets/javascripts/app/views/import/zendesk.jst.eco index 72d538d19..eeb7f95c9 100644 --- a/app/assets/javascripts/app/views/import/zendesk.jst.eco +++ b/app/assets/javascripts/app/views/import/zendesk.jst.eco @@ -61,6 +61,7 @@

<%- @T('%s Migration', 'Zendesk') %>

+
diff --git a/lib/import/zendesk/ticket_factory.rb b/lib/import/zendesk/ticket_factory.rb index 0362f1f41..fbba1fb22 100644 --- a/lib/import/zendesk/ticket_factory.rb +++ b/lib/import/zendesk/ticket_factory.rb @@ -2,6 +2,45 @@ module Import module Zendesk module TicketFactory extend Import::Zendesk::BaseFactory + + # rubocop:disable Style/ModuleFunction + extend self + + private + + def import_loop(records, *args) + + count_update_hook = proc { |record| + yield(record) + update_ticket_count(records) + } + + super(records, *args, &count_update_hook) + end + + def update_ticket_count(collection) + + cache_key = 'import_zendesk_stats' + count_variable = :@count + page_variable = :@next_page + + next_page = collection.instance_variable_get(page_variable) + @last_page ||= next_page + + return if @last_page == next_page + return if !collection.instance_variable_get(count_variable) + + @last_page = next_page + + # check cache + cache = Cache.get(cache_key) + return if !cache + + cache['Tickets'] ||= 0 + cache['Tickets'] += collection.instance_variable_get(count_variable) + + Cache.write(cache_key, cache) + end end end end