From 7d6224979f0213cb531c2a9fa13e8ecd4b589056 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Tue, 16 Sep 2025 23:41:08 +0000 Subject: [PATCH] Reduce requests for issue ID, username, and Wiki page name autocomplete with debounce (#43208). Patch by Katsuya HIDAKA (user:hidakatsuya). git-svn-id: https://svn.redmine.org/redmine/trunk@23978 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/assets/javascripts/application-legacy.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/application-legacy.js b/app/assets/javascripts/application-legacy.js index 917cf9b0a..d73fe440b 100644 --- a/app/assets/javascripts/application-legacy.js +++ b/app/assets/javascripts/application-legacy.js @@ -1257,7 +1257,17 @@ function inlineAutoComplete(element) { } } - const remoteSearch = function(url, cb) { + const debounce = function(func, delay) { + let timeout; + + return function(...args) { + const context = this; + clearTimeout(timeout); + timeout = setTimeout(() => func.apply(context, args), delay); + }; + } + + const remoteSearch = debounce((url, cb) => { const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { @@ -1272,7 +1282,7 @@ function inlineAutoComplete(element) { }; xhr.open("GET", url, true); xhr.send(); - }; + }, 200); const tribute = new Tribute({ collection: [