Skip to content

Commit 1d73cec

Browse files
committed
fix: performance improvement
1 parent 0eeb31c commit 1d73cec

File tree

1 file changed

+63
-28
lines changed

1 file changed

+63
-28
lines changed

src/features/navigation/views/AdminView.vue

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -390,41 +390,76 @@ const filterModeratedSessions = async () => {
390390
});
391391
}
392392
}
393-
393+
394394
filteredModeratedSessions.value = cooperatorArray
395395
};
396396
397397
const filterNextModeratedSessions = async () => {
398-
const userModeratedTests = Object.values(user.value.notifications)
399-
const cooperatorArray = [];
400-
for (const test of userModeratedTests) {
401-
console.log("test", test)
402-
const testObj = await studyController.getStudy({ id: test.testId });
403-
if (testObj) {
404-
const cooperatorObj = testObj.cooperators?.find(coop => coop.userDocId == user.value.id);
405-
if (cooperatorObj) {
406-
Object.assign(cooperatorObj, {
407-
testTitle: testObj.testTitle,
408-
testAdmin: testObj.testAdmin,
409-
id: testObj.id,
410-
testType: testObj.testType,
411-
subType: testObj.subType,
412-
redirectsTo: test.redirectsTo
413-
});
414-
cooperatorArray.push(cooperatorObj);
415-
}
416-
}
417-
}
418-
nextModeratedSessions.value = cooperatorArray
419-
.filter(
420-
(answer) => answer.subType === USER_STUDY_SUBTYPES.MODERATED
421-
)
422-
.filter(
423-
(val, index, self) => index === self.findIndex(m => m.id === val.id)
398+
const userModeratedTests = Object.values(user.value?.notifications || {});
399+
400+
const results = await Promise.all(
401+
userModeratedTests.map(async (test) => {
402+
const testObj = await studyController.getStudy({ id: test.testId });
403+
if (!testObj) return null;
404+
405+
const cooperatorObj = (testObj.cooperators || []).find(
406+
(coop) => coop.userDocId == user.value.id
407+
);
408+
if (!cooperatorObj) return null;
409+
410+
return {
411+
...cooperatorObj,
412+
testTitle: testObj.testTitle,
413+
testAdmin: testObj.testAdmin,
414+
id: testObj.id,
415+
testType: testObj.testType,
416+
subType: testObj.subType,
417+
redirectsTo: test.redirectsTo,
418+
};
419+
})
424420
);
425-
console.log("nextModeratedSessions.value", nextModeratedSessions.value)
421+
422+
// Remove nulos e aplica os mesmos filtros de antes
423+
const cooperatorArray = results.filter(Boolean);
424+
425+
nextModeratedSessions.value = cooperatorArray
426+
.filter((answer) => answer.subType === USER_STUDY_SUBTYPES.MODERATED)
427+
.filter((val, index, self) => index === self.findIndex((m) => m.id === val.id));
428+
429+
console.log("nextModeratedSessions.value", nextModeratedSessions.value);
426430
};
427431
432+
// const filterNextModeratedSessions = async () => {
433+
// const userModeratedTests = Object.values(user.value.notifications)
434+
// const cooperatorArray = [];
435+
// for (const test of userModeratedTests) {
436+
// console.log("test", test)
437+
// const testObj = await studyController.getStudy({ id: test.testId });
438+
// if (testObj) {
439+
// const cooperatorObj = testObj.cooperators?.find(coop => coop.userDocId == user.value.id);
440+
// if (cooperatorObj) {
441+
// Object.assign(cooperatorObj, {
442+
// testTitle: testObj.testTitle,
443+
// testAdmin: testObj.testAdmin,
444+
// id: testObj.id,
445+
// testType: testObj.testType,
446+
// subType: testObj.subType,
447+
// redirectsTo: test.redirectsTo
448+
// });
449+
// cooperatorArray.push(cooperatorObj);
450+
// }
451+
// }
452+
// }
453+
// nextModeratedSessions.value = cooperatorArray
454+
// .filter(
455+
// (answer) => answer.subType === USER_STUDY_SUBTYPES.MODERATED
456+
// )
457+
// .filter(
458+
// (val, index, self) => index === self.findIndex(m => m.id === val.id)
459+
// );
460+
// console.log("nextModeratedSessions.value", nextModeratedSessions.value)
461+
// };
462+
428463
const reloadMyTemplates = async () => {
429464
tempDialog.value = false
430465
await getMyTemplates()

0 commit comments

Comments
 (0)