Introduce LessonIds - #4427
Conversation
- Generate `ModuleLessonMap` after module data is fetched, which stores a map of `RawLesson` to their `LessonId` so that serializeLessonDetails only needs to be called once. - Generate `ModuleLessonMap` for sample modules as well. - Generate `ModuleLessonMap` in the export service so lessons can be rendered. - Currently these are inactive, and would only be used in a future PR.
|
@zehata is attempting to deploy a commit to the modsbot's projects Team on Vercel. A member of the Team first needs to authorize it. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4427 +/- ##
==========================================
+ Coverage 54.52% 56.76% +2.23%
==========================================
Files 274 317 +43
Lines 6076 7059 +983
Branches 1455 1699 +244
==========================================
+ Hits 3313 4007 +694
- Misses 2763 3052 +289 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
…r serialization and deserialization of lessons.
|
@leslieyip02 I have made some changes, and you might want to look at the corresponding changes I made to address the issues that Greptile generated, or retrigger the review. |
leslieyip02
left a comment
There was a problem hiding this comment.
Mostly LGTM, just some minor nits.
|
|
||
| describe('serialize/parse weeks', () => { | ||
| test('serialized weekRange should be deserialized to the same weekRange', () => { | ||
| const weekRanges: WeekRange[] = [ |
There was a problem hiding this comment.
I think we should add 1 more test case where with only start and end. (BME5802 is an example with just start and end in its week range).
| ); | ||
| }; | ||
|
|
||
| const deserializeWeekNumbers = async (serializedWeekNumbers: string): Promise<number[]> => { |
There was a problem hiding this comment.
Does this need to be async?
There was a problem hiding this comment.
No, I don't mind rewriting with try catch
| * @param serializedWeeks | ||
| * @returns | ||
| */ | ||
| export const parseWeeks = async (serializedWeeks: string): Promise<Weeks> => { |
There was a problem hiding this comment.
Does this need to be async?
| * @param lessonsWithLessonType lessons with the same lesson type to generate a valid lesson config from | ||
| * @returns a `ClassNo`. The current implementation generates a config containing the first `ClassNo` | ||
| */ | ||
| export function getRecoveryClassNo(lessonsWithLessonType: Record<LessonId, RawLesson>): LessonId[] { |
There was a problem hiding this comment.
Nit: I think the return type is supposed to be ClassNo.
Also, is there a reason to return LessonId[] instead of a single nullable LessonId? The function name getRecoveryClassNo implies a single return value.
There was a problem hiding this comment.
Ah right, fair point there
| * If weeks is an empty array, the serialized string would be `2025-01-13_2025-02-14_`\ | ||
| * If weeks is undefined, the serialized string would be `2025-01-13_2025-02-14`, without the dangling `_`\ |
There was a problem hiding this comment.
Minor nit: weeks should be enclosed by backticks (i.e. `weeks`).
- Improved regex to better reject malformed strings
…Id`s if any - Added tests for `getRecoverySerializedLessonDetails`
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
ModuleLessonMapafter module data is fetched, which stores a map ofRawLessonto theirLessonIdso that serializeLessonDetails only needs to be called once.ModuleLessonMapfor sample modules as well.ModuleLessonMapin the export service so lessons can be rendered.Context
This is part of the changes meant to fix #4283
Please refer to #4387 for additional info
Implementation
Other than adding the types, it also generates the
ModuleLessonMapwhen modules are downloaded. This memoizes theLessonIdso that they do not have to be generated every time they are used. This also applies to the export service. This also includes a couple of helper functions for serializing and deserializingLessonIds.LessonIds are serialization of all a lesson details, except its module info and lesson type, please refer to #4292 (comment) for why this was chosen.would serialize to
22|TUE|0900|1000|S16-0518|2_3_4_5_6_7_8_9_10_11_12_13.Serialization and deserialization can be quite expensive. So we calculate and store a map of the
LessonTypetoLessonIds to lessons inSemesterData.Other Information
Currently these changes are inactive, they will be used in the a future PR. The delta to switch over to use
LessonIds is already large enough as is.