Performance: Sessions::Backend::TicketOverivewList check whether data has to be sent to the client was wrong. The correct check now compares the list of tickets instead of comparing the whole hash structure including assets.

This commit is contained in:
Martin Edenhofer 2019-10-02 15:57:08 +02:00 committed by Thorsten Eckel
parent d1ed72a071
commit 6018d864db
3 changed files with 33 additions and 58 deletions

View file

@ -89,9 +89,9 @@ class Sessions::Backend::TicketOverviewList < Sessions::Backend::Base
index_and_lists.each do |data| index_and_lists.each do |data|
# do not deliver unchanged lists # do not deliver unchanged lists
next if @last_overview[data[:overview][:id]] == data next if @last_overview[data[:overview][:id]] == [data[:tickets], data[:overview]]
@last_overview[data[:overview][:id]] = data @last_overview[data[:overview][:id]] = [data[:tickets], data[:overview]]
assets = {} assets = {}
overview = Overview.lookup(id: data[:overview][:id]) overview = Overview.lookup(id: data[:overview][:id])

View file

@ -62,8 +62,8 @@ RSpec.describe Sessions::Backend::TicketOverviewList do
end end
context 'when called twice, after changes have occurred to the Ticket table' do context 'when called twice, after changes have occurred to the Ticket table' do
let!(:ticket) { create(:ticket, group: group) }
let!(:first_call) { collection.push } let!(:first_call) { collection.push }
let!(:ticket) { create(:ticket, group: group, owner: admin) }
context 'before the TTL has passed' do context 'before the TTL has passed' do
it 'returns nil' do it 'returns nil' do
@ -73,16 +73,8 @@ RSpec.describe Sessions::Backend::TicketOverviewList do
context 'after .reset with the users id' do context 'after .reset with the users id' do
before { described_class.reset(admin.id) } before { described_class.reset(admin.id) }
it 'returns an updated set of results' do it 'returns nil because no ticket and no overview has changed' do
expect(collection.push) expect(collection.push).to be nil
.to be_an(Array)
.and have_attributes(length: Ticket::Overviews.all(current_user: admin).count)
.and all(match({ event: 'ticket_overview_list', data: hash_including(:assets) }))
end
it 'includes FE assets for the new ticket' do
expect(collection.push.first[:data][:assets]) # first overview is "My assigned tickets",
.to eq(ticket.assets({})) # and newly created ticket was assigned to admin
end end
end end
end end
@ -90,32 +82,16 @@ RSpec.describe Sessions::Backend::TicketOverviewList do
context 'after the TTL has passed' do context 'after the TTL has passed' do
before { travel(ttl + 1) } before { travel(ttl + 1) }
it 'returns an updated set of results' do it 'returns an empty result' do
expect(collection.push) expect(collection.push).to eq nil
.to be_an(Array)
.and have_attributes(length: Ticket::Overviews.all(current_user: admin).count)
.and all(match({ event: 'ticket_overview_list', data: hash_including(:assets) }))
end
it 'includes FE assets for the new ticket' do
expect(collection.push.first[:data][:assets]) # first overview is "My assigned tickets",
.to eq(ticket.assets({})) # and newly created ticket was assigned to admin
end end
end end
context 'after two hours have passed' do context 'after two hours have passed' do
before { travel(2.hours + 1.second) } before { travel(2.hours + 1.second) }
it 'returns an updated set of results' do it 'returns an empty result' do
expect(collection.push) expect(collection.push).to eq nil
.to be_an(Array)
.and have_attributes(length: Ticket::Overviews.all(current_user: admin).count)
.and all(match({ event: 'ticket_overview_list', data: hash_including(:assets) }))
end
it 'includes FE assets for old AND new tickets/overviews' do
expect(collection.push.first[:data][:assets]) # first overview is "My assigned tickets",
.to eq(Overview.first.assets(ticket.assets({}))) # and newly created ticket was assigned to admin
end end
end end
end end
@ -136,40 +112,21 @@ RSpec.describe Sessions::Backend::TicketOverviewList do
it 'returns an updated set of results' do it 'returns an updated set of results' do
expect(collection.push) expect(collection.push)
.to be_an(Array) .to be_an(Array)
.and have_attributes(length: Ticket::Overviews.all(current_user: admin).count) .and have_attributes(length: 1)
.and all(match({ event: 'ticket_overview_list', data: hash_including(:assets) })) .and all(match({ event: 'ticket_overview_list', data: hash_including(:assets) }))
end end
it 'includes FE assets for the touched overview' do
expect(collection.push.first[:data][:assets])
.to eq(Overview.first.assets({}))
end
end
end
context 'after the TTL has passed' do
before { travel(ttl + 1) }
it 'includes FE assets for the touched overview' do
expect(collection.push.first[:data][:assets])
.to eq(Overview.first.assets({}))
end end
end end
context 'after two hours have passed' do context 'after two hours have passed' do
before { travel(2.hours + 1.second) } before { travel(2.hours + 1.second) }
it 'returns an updated set of results' do it 'returns an empty result' do
expect(collection.push) expect(collection.push)
.to be_an(Array) .to be_an(Array)
.and have_attributes(length: Ticket::Overviews.all(current_user: admin).count) .and have_attributes(length: 1)
.and all(match({ event: 'ticket_overview_list', data: hash_including(:assets) })) .and all(match({ event: 'ticket_overview_list', data: hash_including(:assets) }))
end end
it 'includes FE assets for old AND new tickets/overviews' do
expect(collection.push.first[:data][:assets])
.to eq(Overview.first.assets({}))
end
end end
end end
end end

View file

@ -2665,7 +2665,14 @@ wait untill text in selector disabppears
end end
# switch to overview # switch to overview
instance.find_elements(css: ".content.active .sidebar a[href=\"#{link}\"]")[0].click element = nil
6.times do
element = instance.find_elements(css: ".content.active .sidebar a[href=\"#{link}\"]")[0]
break if element
sleep 1
end
element.click
# hide larger overview selection list again # hide larger overview selection list again
sleep 0.5 sleep 0.5
@ -2700,14 +2707,25 @@ wait untill text in selector disabppears
overview_open(params) overview_open(params)
element = nil
if params[:title] if params[:title]
6.times do
element = instance.find_element(css: '.content.active').find_element(partial_link_text: params[:title]) element = instance.find_element(css: '.content.active').find_element(partial_link_text: params[:title])
break if element
sleep 1
end
if !element if !element
screenshot(browser: instance, comment: 'ticket_open_by_overview_no_ticket_failed') screenshot(browser: instance, comment: 'ticket_open_by_overview_no_ticket_failed')
raise "unable to find ticket #{params[:title]} in overview #{params[:link]}!" raise "unable to find ticket #{params[:title]} in overview #{params[:link]}!"
end end
else else
6.times do
element = instance.find_elements(partial_link_text: params[:number])[0] element = instance.find_elements(partial_link_text: params[:number])[0]
break if element
sleep 1
end
if !element if !element
screenshot(browser: instance, comment: 'ticket_open_by_overview_no_ticket_failed') screenshot(browser: instance, comment: 'ticket_open_by_overview_no_ticket_failed')
raise "unable to find ticket #{params[:number]} in overview #{params[:link]}!" raise "unable to find ticket #{params[:number]} in overview #{params[:link]}!"