From 3ba5d5ff8b5699f7c65e73293caa338a500ef22b Mon Sep 17 00:00:00 2001 From: Katsuya HIDAKA Date: Sun, 14 Sep 2025 02:24:50 +0900 Subject: Reduce requests for issue ID, username, and Wiki page name autocomplete with debounce --- 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..a2802dc6e 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(); - }; + }, 300); const tribute = new Tribute({ collection: [ -- 2.51.0