Skip to content

Commit 745cfc8

Browse files
committed
use hydrated card stack for nextQ
1 parent 1f54475 commit 745cfc8

File tree

2 files changed

+24
-59
lines changed

2 files changed

+24
-59
lines changed

agent/nextCard-perf/a.4.todo.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ This file breaks down the tasks required to implement the client-side pre-fetchi
2525

2626
## Phase 4: UI and Verification
2727

28-
- [ ] **Task 4.1:** Adjust the UI component that calls `nextCard()` to expect the new `HydratedCard` object, removing its own data-fetching logic.
29-
- [ ] **Task 4.2:** Manually test the study session flow to confirm that cards load quickly and that there are no errors.
30-
- [ ] **Task 4.3:** Use browser developer tools to verify that network requests for card data are happening *before* a card is displayed, not when it is requested.
28+
- [x] **Task 4.1:** Adjust the UI component that calls `nextCard()` to expect the new `HydratedCard` object, removing its own data-fetching logic.
29+
- [x] **Task 4.2:** Manually test the study session flow to confirm that cards load quickly and that there are no errors.
30+
- [x] **Task 4.3:** Use browser developer tools to verify that network requests for card data are happening *before* a card is displayed, not when it is requested.

packages/common-ui/src/components/StudySession.vue

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,17 @@ import {
8181
StudyContentSource,
8282
StudySessionItem,
8383
docIsDeleted,
84-
CardData,
8584
CardHistory,
8685
CardRecord,
87-
DisplayableData,
8886
isQuestionRecord,
8987
CourseRegistrationDoc,
9088
DataLayerProvider,
9189
UserDBInterface,
9290
ClassroomDBInterface,
9391
} from '@vue-skuilder/db';
94-
import { SessionController, StudySessionRecord } from '@vue-skuilder/db';
92+
import { HydratedCard, SessionController, StudySessionRecord } from '@vue-skuilder/db';
9593
import { newInterval } from '@vue-skuilder/db';
96-
import {
97-
adjustCourseScores,
98-
CourseElo,
99-
toCourseElo,
100-
isCourseElo,
101-
displayableDataToViewData,
102-
ViewData,
103-
Status,
104-
} from '@vue-skuilder/common';
94+
import { adjustCourseScores, CourseElo, toCourseElo, ViewData, Status } from '@vue-skuilder/common';
10595
import confetti from 'canvas-confetti';
10696
import moment from 'moment';
10797
@@ -555,78 +545,53 @@ export default defineComponent({
555545
});
556546
},
557547
558-
async loadCard(item: StudySessionItem | null) {
548+
async loadCard(card: HydratedCard | null) {
559549
if (this.loading) {
560550
console.warn(`Attempted to load card while loading another...`);
561551
return;
562552
}
563553
564-
console.log(`[StudySession] loading: ${JSON.stringify(item)}`);
565-
if (item === null) {
554+
console.log(`[StudySession] loading: ${JSON.stringify(card)}`);
555+
if (card === null) {
566556
this.sessionFinished = true;
567557
this.$emit('session-finished', this.sessionRecord);
568558
return;
569559
}
570-
this.cardType = item.status;
560+
this.cardType = card.item.status;
571561
572562
this.loading = true;
573-
const _courseID = item.courseID;
574-
const _cardID = item.cardID;
575-
576-
console.log(`[StudySession] Now displaying: ${_courseID}::${_cardID}`);
577563
578564
try {
579-
const tmpCardData = await this.dataLayer.getCourseDB(_courseID).getCourseDoc<CardData>(_cardID);
580-
581-
if (!isCourseElo(tmpCardData.elo)) {
582-
tmpCardData.elo = toCourseElo(tmpCardData.elo);
583-
}
584-
585-
const tmpView: ViewComponent = this.getViewComponent(tmpCardData.id_view);
586-
const tmpDataDocs = tmpCardData.id_displayable_data.map((id) => {
587-
return this.dataLayer.getCourseDB(_courseID).getCourseDoc<DisplayableData>(id, {
588-
attachments: true,
589-
binary: true,
590-
});
591-
});
592-
593-
const tmpData = [];
594-
595-
for (const docPromise of tmpDataDocs) {
596-
const doc = await docPromise;
597-
tmpData.unshift(displayableDataToViewData(doc));
598-
}
599-
600565
this.cardCount++;
601-
this.data = tmpData;
602-
this.view = markRaw(tmpView);
603-
this.cardID = _cardID;
604-
this.courseID = _courseID;
605-
this.card_elo = tmpCardData.elo.global.score;
566+
this.data = card.data;
567+
this.view = markRaw(card.view);
568+
this.cardID = card.item.cardID;
569+
this.courseID = card.item.courseID;
570+
this.card_elo = card.item.elo || 1000;
606571
607572
this.sessionRecord.push({
608573
card: {
609-
course_id: _courseID,
610-
card_id: _cardID,
611-
card_elo: tmpCardData.elo.global.score,
574+
course_id: card.item.courseID,
575+
card_id: card.item.cardID,
576+
card_elo: this.card_elo,
612577
},
613-
item: item,
578+
item: card.item,
614579
records: [],
615580
});
616581
617582
this.$emit('card-loaded', {
618-
courseID: _courseID,
619-
cardID: _cardID,
583+
courseID: card.item.courseID,
584+
cardID: card.item.cardID,
620585
cardCount: this.cardCount,
621586
});
622587
} catch (e) {
623-
console.warn(`[StudySession] Error loading card ${JSON.stringify(item)}:\n\t${JSON.stringify(e)}, ${e}`);
588+
console.warn(`[StudySession] Error loading card ${JSON.stringify(card)}:\n\t${JSON.stringify(e)}, ${e}`);
624589
this.loading = false;
625590
626591
const err = e as Error;
627-
if (docIsDeleted(err) && isReview(item)) {
628-
console.warn(`Card was deleted: ${_courseID}::${_cardID}`);
629-
this.user!.removeScheduledCardReview(item.reviewID);
592+
if (docIsDeleted(err) && isReview(card.item)) {
593+
console.warn(`Card was deleted: ${card.item.courseID}::${card.item.cardID}`);
594+
this.user!.removeScheduledCardReview((card.item as any).reviewID);
630595
}
631596
632597
this.loadCard(this.sessionController!.nextCard('dismiss-error'));

0 commit comments

Comments
 (0)