From e9a48487c0725638851513f69aedf9d8ebd0966f Mon Sep 17 00:00:00 2001 From: sunnavy Date: Thu, 12 Dec 2024 12:34:01 -0500 Subject: [PATCH] No need to update recipients/scrips if the form data doesn't actually change It's possible that we trigger "change" event even if the input value doesn't actually change. E.g. dragging a recipient and dropping it to its original position triggers "change" event. When things like that happen, recipients/scrips are the same, so it's safe to not fetch them again. --- share/static/js/util.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/share/static/js/util.js b/share/static/js/util.js index 2eaad5167e..6e649e1929 100644 --- a/share/static/js/util.js +++ b/share/static/js/util.js @@ -1820,6 +1820,7 @@ function checkRefreshState(elt) { } let _ticket_preparing_recipients = 0; +let _ticket_update_recipients_data; function ticketUpdateRecipients(evt) { if ( evt && evt.type === 'htmx:load' ) { if ( document.querySelector('.htmx-indicator') ) { @@ -1853,14 +1854,17 @@ function ticketUpdateRecipients(evt) { } _ticket_preparing_recipients = 1; - jQuery('.ticket-info-recipients div.titlebox-content').addClass('refreshing'); - // Wait a little bit in case user leaves related inputs(which // could fire ticketUpdate...) by checking/unchecking recipient // checkboxes, this is to get checkboxes' latest status setTimeout(function() { _ticket_preparing_recipients = 0; var payload = jQuery('form[name=TicketUpdate]').serializeArray(); + if ( JSON.stringify(payload) === _ticket_update_recipients_data ) { + return; + } + _ticket_update_recipients_data = JSON.stringify(payload); + jQuery('.ticket-info-recipients div.titlebox-content').addClass('refreshing'); jQuery('.ticket-info-recipients div.titlebox-content div.card-body').load(RT.Config.WebPath + '/Helpers/ShowSimplifiedRecipients', payload, @@ -1883,6 +1887,7 @@ function ticketUpdateRecipients(evt) { } let _ticket_preparing_scrips = 0; +let _ticket_update_scrips_data; function ticketUpdateScrips(evt) { if ( evt && evt.type === 'htmx:load' ) { if ( document.querySelector('.htmx-indicator') ) { @@ -1916,7 +1921,6 @@ function ticketUpdateScrips(evt) { } _ticket_preparing_scrips = 1; - jQuery('.ticket-info-preview-scrips div.titlebox-content').addClass('refreshing'); // Wait a little bit in case user leaves related inputs(which // could fire ticketUpdate...) by checking/unchecking recipient @@ -1924,6 +1928,11 @@ function ticketUpdateScrips(evt) { setTimeout(function() { _ticket_preparing_scrips = 0; var payload = jQuery('form[name=TicketUpdate]').serializeArray(); + if ( JSON.stringify(payload) === _ticket_update_scrips_data ) { + return; + } + _ticket_update_scrips_data = JSON.stringify(payload); + jQuery('.ticket-info-preview-scrips div.titlebox-content').addClass('refreshing'); jQuery('.ticket-info-preview-scrips div.titlebox-content div.card-body').load(RT.Config.WebPath + '/Helpers/PreviewScrips', payload,