Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2020-12-16 12:41:41 +0300
committerJulius Härtl <jus@bitgrid.net>2020-12-16 14:38:33 +0300
commit915d4375126990cbb3189832f59e0d7730e1a867 (patch)
tree3062bbf4fac66d0cf13d3f554d714506819e3eb0 /apps/settings/src
parentd613450e4ed44f976a2f6d3fea7115a6a80d6122 (diff)
Cancel user search requests to avoid duplicate results being added
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/settings/src')
-rw-r--r--apps/settings/src/store/api.js4
-rw-r--r--apps/settings/src/store/users.js28
2 files changed, 26 insertions, 6 deletions
diff --git a/apps/settings/src/store/api.js b/apps/settings/src/store/api.js
index ef2a51b2a15..9a03fe68ef9 100644
--- a/apps/settings/src/store/api.js
+++ b/apps/settings/src/store/api.js
@@ -63,8 +63,8 @@ export default {
requireAdmin() {
return confirmPassword()
},
- get(url) {
- return axios.get(sanitize(url))
+ get(url, options) {
+ return axios.get(sanitize(url), options)
},
post(url, data) {
return axios.post(sanitize(url), data)
diff --git a/apps/settings/src/store/users.js b/apps/settings/src/store/users.js
index e24996305a0..3f87f5b0040 100644
--- a/apps/settings/src/store/users.js
+++ b/apps/settings/src/store/users.js
@@ -21,6 +21,7 @@
*/
import api from './api'
+import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
const orderGroups = function(groups, orderBy) {
@@ -189,6 +190,9 @@ const getters = {
},
}
+const CancelToken = axios.CancelToken
+let searchRequestCancelSource = null
+
const actions = {
/**
@@ -203,10 +207,16 @@ const actions = {
* @returns {Promise}
*/
getUsers(context, { offset, limit, search, group }) {
+ if (searchRequestCancelSource) {
+ searchRequestCancelSource.cancel('Operation canceled by another search request.')
+ }
+ searchRequestCancelSource = CancelToken.source()
search = typeof search === 'string' ? search : ''
group = typeof group === 'string' ? group : ''
if (group !== '') {
- return api.get(generateOcsUrl(`cloud/groups/${encodeURIComponent(encodeURIComponent(group))}/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2))
+ return api.get(generateOcsUrl(`cloud/groups/${encodeURIComponent(encodeURIComponent(group))}/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2), {
+ cancelToken: searchRequestCancelSource.token,
+ })
.then((response) => {
if (Object.keys(response.data.ocs.data.users).length > 0) {
context.commit('appendUsers', response.data.ocs.data.users)
@@ -214,10 +224,16 @@ const actions = {
}
return false
})
- .catch((error) => context.commit('API_FAILURE', error))
+ .catch((error) => {
+ if (!axios.isCancel(error)) {
+ context.commit('API_FAILURE', error)
+ }
+ })
}
- return api.get(generateOcsUrl(`cloud/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2))
+ return api.get(generateOcsUrl(`cloud/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2), {
+ cancelToken: searchRequestCancelSource.token,
+ })
.then((response) => {
if (Object.keys(response.data.ocs.data.users).length > 0) {
context.commit('appendUsers', response.data.ocs.data.users)
@@ -225,7 +241,11 @@ const actions = {
}
return false
})
- .catch((error) => context.commit('API_FAILURE', error))
+ .catch((error) => {
+ if (!axios.isCancel(error)) {
+ context.commit('API_FAILURE', error)
+ }
+ })
},
getGroups(context, { offset, limit, search }) {