Skip to content

Commit 690fdf9

Browse files
author
Stanislav Idolov
authored
ENGCOM-2245: Prevent servers being slammed from many search suggestion requests #16669
2 parents d1db68d + 66b49e3 commit 690fdf9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

app/code/Magento/Search/view/frontend/web/form-mini.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ define([
4343
'</li>',
4444
submitBtn: 'button[type="submit"]',
4545
searchLabel: '[data-role=minisearch-label]',
46-
isExpandable: null
46+
isExpandable: null,
47+
suggestionDelay: 300
4748
},
4849

4950
/** @inheritdoc */
@@ -104,7 +105,8 @@ define([
104105

105106
this.element.on('focus', this.setActiveState.bind(this, true));
106107
this.element.on('keydown', this._onKeyDown);
107-
this.element.on('input propertychange', this._onPropertyChange);
108+
// Prevent spamming the server with requests by waiting till the user has stopped typing for period of time
109+
this.element.on('input propertychange', _.debounce(this._onPropertyChange, this.options.suggestionDelay));
108110

109111
this.searchForm.on('submit', $.proxy(function (e) {
110112
this._onSubmit(e);

0 commit comments

Comments
 (0)