Skip to content

Commit

Permalink
detect malformed study chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Feb 9, 2018
1 parent 9fae708 commit 7a06225
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bin/mongodb/study-chapter-depth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
rs.slaveOk();
var depth, maxDepth = 900;

function depthOf(branch) { return 2 + Math.max(...(branch.n || []).map(depthOf),0); }

function urlOf(chap) {
var study = db.study.findOne({_id:chap.studyId});
return `https://lichess.org/study/${study._id}/${chap._id} by ${study.ownerId}`;
}

db.study_chapter.find().forEach(chap => {
try {
depth = depthOf(chap.root);
if (depth > maxDepth) print(`${urlOf(chap)} ${depth}`);
} catch(e) {
print(`${urlOf(chap)} ${e}`);
}
})

0 comments on commit 7a06225

Please sign in to comment.