Skip to content

Commit

Permalink
Optimize fetching users data
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVelezLl committed Jun 25, 2024
1 parent 3bf2354 commit 0f51871
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions kolibri/plugins/device/assets/src/users/composables/useUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0f51871

Please sign in to comment.