Working on issue #1161 - Count of Tickets in Zendesk import state overview is wrong due rate limit of 1000 tickets per batch.
This commit is contained in:
parent
c25d7507d5
commit
7a142a5467
3 changed files with 45 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
<div class="wizard-slide vertical hide" data-slide="zendesk-import">
|
||||
<h2><%- @T('%s Migration', 'Zendesk') %></h2>
|
||||
<div class="alert alert--danger hide js-error" role="alert"></div>
|
||||
<div class="alert alert--info hide js-ticket-count-info" role="alert"><%- @T("There are more than 1000 tickets in the Zendesk system. Due to API rate limit restrictions we can't get the exact number of tickets yet and have to fetch them in batches of 1000. This might take some time, better grab a cup of coffee. The total number of tickets gets updated as soon as the currently known number is surpassed.") %></div>
|
||||
<div class="wizard-body flex vertical justified">
|
||||
<table class="progressTable">
|
||||
<tr class="js-group">
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue