From 0f5187132bdcd6378c7bc6fb3776155ec4a4869c Mon Sep 17 00:00:00 2001 From: Alex Velez Date: Tue, 25 Jun 2024 16:18:58 -0500 Subject: [PATCH] Optimize fetching users data --- .../assets/src/users/composables/useUsers.js | 20 +++++++++---------- .../assets/src/users/views/UsersPage.vue | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/kolibri/plugins/device/assets/src/users/composables/useUsers.js b/kolibri/plugins/device/assets/src/users/composables/useUsers.js index 2d86ca476a9..5138ea75688 100644 --- a/kolibri/plugins/device/assets/src/users/composables/useUsers.js +++ b/kolibri/plugins/device/assets/src/users/composables/useUsers.js @@ -7,23 +7,23 @@ import { deviceString } from '../../views/commonDeviceStrings'; const isPooling = ref(false); const usersBeingImportedRef = ref([]); +const users = ref([]); +const loading = ref(true); +const showCannotRemoveUser = ref(false); export default function useUsers() { const store = getCurrentInstance().proxy.$store; const importUserService = inject('importUserService') || {}; - const users = ref([]); - const loading = ref(true); - const showCannotRemoveUser = ref(false); - async function fetchUsers() { + async function fetchUsers({ force } = {}) { loading.value = true; const response = await FacilityUserResource.fetchCollection({ - force: true, + force, }); - users.value = response; - users.value.forEach(user => { + response.forEach(user => { user.kind = UserType(user); }); + users.value = response; store.dispatch('notLoading'); loading.value = false; } @@ -70,7 +70,7 @@ export default function useUsers() { tasksMap[task.extra_metadata.user_id] = task; }); - usersBeingImported.forEach(user => { + usersBeingImported.forEach(async user => { const task = tasksMap[user.id]; if (!task) { return; @@ -87,8 +87,8 @@ export default function useUsers() { value: user.id, }); usersBeingImportedRef.value = getUsersBeingImported(); - fetchUsers(); - TaskResource.clear(task.id); + await TaskResource.clear(task.id); + fetchUsers({ force: true }); } }); setTimeout(() => { diff --git a/kolibri/plugins/device/assets/src/users/views/UsersPage.vue b/kolibri/plugins/device/assets/src/users/views/UsersPage.vue index cf120d16d4a..5a36de5d059 100644 --- a/kolibri/plugins/device/assets/src/users/views/UsersPage.vue +++ b/kolibri/plugins/device/assets/src/users/views/UsersPage.vue @@ -124,7 +124,7 @@ try { await this.removeUser(userId); this.userIdToRemove = null; - await this.fetchUsers(); + await this.fetchUsers({ force: true }); } catch (error) { this.userIdToRemove = null; }