FIX: remove racing requests for admin users (#15936)

This commit is contained in:
Mark VanLandingham 2022-03-16 08:47:48 -05:00 committed by GitHub
parent 704606e731
commit a0f4c7fe88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@ export default Controller.extend(CanCheckEmails, {
listFilter: null, listFilter: null,
selectAll: false, selectAll: false,
searchHint: i18n("search_hint"), searchHint: i18n("search_hint"),
_searchIndex: 0,
init() { init() {
this._super(...arguments); this._super(...arguments);
@ -48,6 +49,8 @@ export default Controller.extend(CanCheckEmails, {
return; return;
} }
this._searchIndex++;
const searchIndex = this._searchIndex;
this.set("refreshing", true); this.set("refreshing", true);
AdminUser.findAll(this.query, { AdminUser.findAll(this.query, {
@ -58,6 +61,10 @@ export default Controller.extend(CanCheckEmails, {
page: this._page, page: this._page,
}) })
.then((result) => { .then((result) => {
if (this.ignoreResponse(searchIndex)) {
return;
}
if (!result || result.length === 0) { if (!result || result.length === 0) {
this._canLoadMore = false; this._canLoadMore = false;
} }
@ -65,7 +72,18 @@ export default Controller.extend(CanCheckEmails, {
this._results = this._results.concat(result); this._results = this._results.concat(result);
this.set("model", this._results); this.set("model", this._results);
}) })
.finally(() => this.set("refreshing", false)); .finally(() => {
if (this.ignoreResponse(searchIndex)) {
return;
}
this.set("refreshing", false);
});
},
ignoreResponse(searchIndex) {
return (
searchIndex !== this._searchIndex || this.isDestroyed || this.isDestroying
);
}, },
actions: { actions: {