mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
fix
This commit is contained in:
+14
-3
@@ -31,6 +31,9 @@ function estimateBlockDuration(block) {
|
||||
case "document":
|
||||
return readingSecs(block.content?.body);
|
||||
|
||||
case "code":
|
||||
return readingSecs(block.content?.code);
|
||||
|
||||
case "image":
|
||||
return 60;
|
||||
|
||||
@@ -95,16 +98,24 @@ async function recomputeCourseDuration(courseId) {
|
||||
* Recompute and persist duration_seconds up the chain:
|
||||
* blocks → lesson → every attached unit → every course those units are attached to.
|
||||
* A lesson may live in many units, and a unit in many courses, so all parents refresh.
|
||||
*
|
||||
* `blocksOverride` lets a caller that just wrote the page (e.g. upsertLessonPage,
|
||||
* which already has the upserted row in hand) skip the re-read — avoids relying on
|
||||
* read-after-write visibility of the just-committed upsert.
|
||||
*/
|
||||
async function recomputeDurations(lessonId) {
|
||||
async function recomputeDurations(lessonId, blocksOverride = null) {
|
||||
const Lesson = require("../models/courses/lessons.mdl");
|
||||
const LessonPage = require("../models/courses/lesson_page.mdl");
|
||||
const UnitLesson = require("../models/courses/unit_lessons.mdl");
|
||||
const CourseUnit = require("../models/courses/course_units.mdl");
|
||||
|
||||
// 1. Lesson duration from blocks
|
||||
const page = await LessonPage.findOne({ where: { lesson_id: lessonId } });
|
||||
const lessonSecs = (page?.blocks ?? []).reduce(
|
||||
let blocks = blocksOverride;
|
||||
if (!blocks) {
|
||||
const page = await LessonPage.findOne({ where: { lesson_id: lessonId } });
|
||||
blocks = page?.blocks ?? [];
|
||||
}
|
||||
const lessonSecs = blocks.reduce(
|
||||
(sum, block) => sum + estimateBlockDuration(block), 0
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user