Skip to content

Commit 75d2dbf

Browse files
committed
add dbg info helper
1 parent c2d6602 commit 75d2dbf

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

packages/db/src/impl/common/BaseUserDB.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,12 +722,22 @@ Currently logged-in as ${this._username}.`
722722

723723
/**
724724
* Logs a record of the user's interaction with the card and returns the card's
725-
* up-to-date history
725+
* up-to-date history.
726+
*
727+
* **Automatic Initialization:**
728+
* If this is the user's first interaction with the card (CardHistory doesn't exist),
729+
* this method automatically creates the CardHistory document with initial values
730+
* (lapses: 0, streak: 0, bestInterval: 0).
731+
*
732+
* **Error Handling:**
733+
* - Handles 404 errors by creating initial CardHistory document
734+
* - Re-throws all other errors from UpdateQueue
726735
*
727736
* // [ ] #db-refactor extract to a smaller scope - eg, UserStudySession
728737
*
729-
* @param record the recent recorded interaction between user and card
738+
* @param record - The recent recorded interaction between user and card
730739
* @returns The updated state of the card's CardHistory data
740+
* @throws Error if document creation fails or non-404 database error occurs
731741
*/
732742

733743
public async putCardRecord<T extends CardRecord>(

packages/db/src/study/SessionController.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,56 @@ export class SessionController<TView = unknown> extends Loggable {
208208
return `${this.reviewQ.dequeueCount} Reviews, ${this.newQ.dequeueCount} New, ${this.failedQ.dequeueCount} failed`;
209209
}
210210

211+
/**
212+
* Returns debug information about the current session state.
213+
* Used by SessionControllerDebug component for runtime inspection.
214+
*/
215+
public getDebugInfo() {
216+
const extractQueueItems = (queue: ItemQueue<any>, limit: number = 10) => {
217+
const items = [];
218+
for (let i = 0; i < Math.min(queue.length, limit); i++) {
219+
const item = queue.peek(i);
220+
items.push({
221+
courseID: item.courseID || 'unknown',
222+
cardID: item.cardID || 'unknown',
223+
status: item.status || 'unknown',
224+
});
225+
}
226+
return items;
227+
};
228+
229+
const extractHydratedItems = (limit: number = 10) => {
230+
const items = [];
231+
const hydratedCount = this.hydrationService.hydratedCount;
232+
// We can't easily iterate the hydrated queue without dequeuing,
233+
// so we'll just report the count
234+
return items;
235+
};
236+
237+
return {
238+
reviewQueue: {
239+
length: this.reviewQ.length,
240+
dequeueCount: this.reviewQ.dequeueCount,
241+
items: extractQueueItems(this.reviewQ),
242+
},
243+
newQueue: {
244+
length: this.newQ.length,
245+
dequeueCount: this.newQ.dequeueCount,
246+
items: extractQueueItems(this.newQ),
247+
},
248+
failedQueue: {
249+
length: this.failedQ.length,
250+
dequeueCount: this.failedQ.dequeueCount,
251+
items: extractQueueItems(this.failedQ),
252+
},
253+
hydratedCache: {
254+
count: this.hydrationService.hydratedCount,
255+
failedCacheSize: this.hydrationService.failedCacheSize,
256+
items: extractHydratedItems(),
257+
},
258+
};
259+
}
260+
211261
private async getScheduledReviews() {
212262
const reviews = await Promise.all(
213263
this.sources.map((c) =>

0 commit comments

Comments
 (0)