Skip to content

Commit

Permalink
WEBUI-1120: make quick search debounce requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshkumar1019 committed Jun 8, 2023
1 parent f39ec9c commit 6dff339
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion elements/nuxeo-suggester/nuxeo-suggester.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ Polymer({
},
searchDelay: {
type: Number,
value: 200,
value: 500,
},
target: {
type: Object,
Expand Down

1 comment on commit 6dff339

@Elanouette-STM
Copy link

@Elanouette-STM Elanouette-STM commented on 6dff339 Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rakeshkumar1019
Kind of quick win fix but only delay a little the display of results and in the end didn't fix at all the root cause of the initial issue reported in SUPNXP-34884 :
Results from "Ele" come after 5 secondes so it override the one for the complete word "Elexir" that take 2 seconds to complete. Here a 500ms debounce value won't change anything. It's about the logic not the params.

A good fix would be to define 2 new integer properties on the element :

  • lastQueryId
  • lastCompletedQueryId

Then update the _searchTermChanged function with something like this

`_searchTermChanged: function() {
this.$.selector.selected = 0;
const currentQuery = this.searchTerm;
const currentQueryId = ++this.lastQueryId; // increment and get a unique ID for this query

if (this.searchTerm === '') {
this.items = [];
} else {
this.debounce('suggester-search', function() {
this.$.op.execute().then(function() {
// Check if this query is later than the last completed query
if (currentQueryId >= this.lastCompletedQueryId) {
this.lastCompletedQueryId = currentQueryId; // Update the last completed query ID
// ... your existing logic to populate this.items
}
}.bind(this));
}.bind(this), this.searchDelay);
}
};`

this insure that you display results in the order of the queries made, but skip any results that return out-of-order, i.e., if a newer query has already returned results

Please sign in to comment.