study code tweaks
parent
d4699c2056
commit
9da6ba5973
|
@ -78,31 +78,23 @@ final class ChapterRepo(coll: Coll) {
|
|||
def setTagsFor(chapter: Chapter) =
|
||||
coll.updateField($id(chapter.id), "tags", chapter.tags).void
|
||||
|
||||
def setShapes(chapter: Chapter, path: Path, shapes: lila.tree.Node.Shapes): Funit =
|
||||
setNodeValue(chapter, path, "h", shapes.value.nonEmpty option shapes)
|
||||
def setShapes(shapes: lila.tree.Node.Shapes) = setNodeValue("h", shapes.value.nonEmpty option shapes) _
|
||||
|
||||
def setComments(chapter: Chapter, path: Path, comments: lila.tree.Node.Comments): Funit =
|
||||
setNodeValue(chapter, path, "co", comments.value.nonEmpty option comments)
|
||||
def setComments(comments: lila.tree.Node.Comments) = setNodeValue("co", comments.value.nonEmpty option comments) _
|
||||
|
||||
def setGamebook(chapter: Chapter, path: Path, gamebook: lila.tree.Node.Gamebook): Funit =
|
||||
setNodeValue(chapter, path, "ga", gamebook.nonEmpty option gamebook)
|
||||
def setGamebook(gamebook: lila.tree.Node.Gamebook) = setNodeValue("ga", gamebook.nonEmpty option gamebook) _
|
||||
|
||||
def setGlyphs(chapter: Chapter, path: Path, glyphs: chess.format.pgn.Glyphs): Funit =
|
||||
setNodeValue(chapter, path, "g", glyphs.nonEmpty)
|
||||
def setGlyphs(glyphs: chess.format.pgn.Glyphs) = setNodeValue("g", glyphs.nonEmpty) _
|
||||
|
||||
def setClock(chapter: Chapter, path: Path, clock: Option[chess.Centis]): Funit =
|
||||
setNodeValue(chapter, path, "l", clock)
|
||||
def setClock(clock: Option[chess.Centis]) = setNodeValue("l", clock) _
|
||||
|
||||
def forceVariation(chapter: Chapter, path: Path, force: Boolean): Funit =
|
||||
setNodeValue(chapter, path, "fv", force option true)
|
||||
def forceVariation(force: Boolean) = setNodeValue("fv", force option true) _
|
||||
|
||||
def setScore(chapter: Chapter, path: Path, score: Option[lila.tree.Eval.Score]): Funit =
|
||||
setNodeValue(chapter, path, "e", score)
|
||||
def setScore(score: Option[lila.tree.Eval.Score]) = setNodeValue("e", score) _
|
||||
|
||||
def setChildren(chapter: Chapter, path: Path, children: Node.Children): Funit =
|
||||
setNodeValue(chapter, path, "n", children.some)
|
||||
def setChildren(children: Node.Children) = setNodeValue("n", children.some) _
|
||||
|
||||
private def setNodeValue[A: BSONValueWriter](chapter: Chapter, path: Path, field: String, value: Option[A]): Funit =
|
||||
private def setNodeValue[A: BSONValueWriter](field: String, value: Option[A])(chapter: Chapter, path: Path): Funit =
|
||||
pathToField(chapter, path, field) match {
|
||||
case None =>
|
||||
logger.warn(s"Can't setNodeValue ${chapter.id} $path $field")
|
||||
|
|
|
@ -51,18 +51,16 @@ object ServerEval {
|
|||
(complete ?? chapterRepo.completeServerEval(chapter)) >> {
|
||||
lila.common.Future.fold(chapter.root.mainline zip analysis.infoAdvices)(Path.root) {
|
||||
case (path, (node, (info, advOpt))) => info.eval.score.ifTrue(node.score.isEmpty).?? { score =>
|
||||
chapterRepo.setScore(chapter, path + node, score.some) >>
|
||||
chapterRepo.setScore(score.some)(chapter, path + node) >>
|
||||
advOpt.?? { adv =>
|
||||
chapterRepo.setComments(chapter, path + node, node.comments + Comment(
|
||||
chapterRepo.setComments(node.comments + Comment(
|
||||
Comment.Id.make,
|
||||
Comment.Text(adv.makeComment(false, true)),
|
||||
Comment.Author.Lichess
|
||||
)) >>
|
||||
))(chapter, path + node) >>
|
||||
chapterRepo.setGlyphs(
|
||||
chapter,
|
||||
path + node,
|
||||
node.glyphs merge Glyphs.fromList(List(adv.judgment.glyph))
|
||||
) >> {
|
||||
)(chapter, path + node) >> {
|
||||
chapter.root.nodeAt(path).flatMap { parent =>
|
||||
analysisLine(parent, chapter.setup.variant, info) flatMap { child =>
|
||||
parent.addChild(child).children.get(child.id)
|
||||
|
|
|
@ -194,7 +194,7 @@ final class StudyApi(
|
|||
case Some(chapter) =>
|
||||
chapter.root.nodeAt(position.path) ?? { parent =>
|
||||
val newPosition = position.ref + node
|
||||
chapterRepo.setChildren(chapter, position.path, parent.children) >>
|
||||
chapterRepo.setChildren(parent.children)(chapter, position.path) >>
|
||||
(relay ?? { chapterRepo.setRelay(chapter.id, _) }) >>
|
||||
(opts.sticky ?? studyRepo.setPosition(study.id, newPosition)) >>
|
||||
updateConceal(study, chapter, newPosition) >>- {
|
||||
|
@ -283,7 +283,7 @@ final class StudyApi(
|
|||
private def doForceVariation(sc: Study.WithChapter, path: Path, force: Boolean, sri: Sri): Funit =
|
||||
sc.chapter.forceVariation(force, path) match {
|
||||
case Some(newChapter) =>
|
||||
chapterRepo.forceVariation(newChapter, path, force) >>-
|
||||
chapterRepo.forceVariation(force)(newChapter, path) >>-
|
||||
sendTo(sc.study, StudySocket.ForceVariation(Position(newChapter, path).ref, force, sri))
|
||||
case None =>
|
||||
fufail(s"Invalid forceVariation ${Position(sc.chapter, path)} $force") >>-
|
||||
|
@ -339,7 +339,7 @@ final class StudyApi(
|
|||
chapter.setShapes(shapes, position.path) match {
|
||||
case Some(newChapter) =>
|
||||
studyRepo.updateNow(study)
|
||||
chapterRepo.setShapes(newChapter, position.path, shapes) >>-
|
||||
chapterRepo.setShapes(shapes)(newChapter, position.path) >>-
|
||||
sendTo(study, StudySocket.SetShapes(position, shapes, sri))
|
||||
case None =>
|
||||
fufail(s"Invalid setShapes $position $shapes") >>-
|
||||
|
@ -355,7 +355,7 @@ final class StudyApi(
|
|||
sc.chapter.setClock(clock, position.path) match {
|
||||
case Some(newChapter) =>
|
||||
studyRepo.updateNow(sc.study)
|
||||
chapterRepo.setClock(newChapter, position.path, clock) >>-
|
||||
chapterRepo.setClock(clock)(newChapter, position.path) >>-
|
||||
sendTo(sc.study, StudySocket.SetClock(position, clock, sri))
|
||||
case None =>
|
||||
fufail(s"Invalid setClock $position $clock") >>-
|
||||
|
@ -406,7 +406,7 @@ final class StudyApi(
|
|||
studyRepo.updateNow(study)
|
||||
newChapter.root.nodeAt(position.path) ?? { node =>
|
||||
node.comments.findBy(comment.by) ?? { c =>
|
||||
chapterRepo.setComments(newChapter, position.path, node.comments.filterEmpty) >>- {
|
||||
chapterRepo.setComments(node.comments.filterEmpty)(newChapter, position.path) >>- {
|
||||
sendTo(study, StudySocket.SetComment(position.ref, c, sri))
|
||||
indexStudy(study)
|
||||
sendStudyEnters(study, userId)
|
||||
|
@ -438,7 +438,7 @@ final class StudyApi(
|
|||
case Some(newChapter) =>
|
||||
studyRepo.updateNow(study)
|
||||
newChapter.root.nodeAt(position.path) ?? { node =>
|
||||
chapterRepo.setGlyphs(newChapter, position.path, node.glyphs) >>-
|
||||
chapterRepo.setGlyphs(node.glyphs)(newChapter, position.path) >>-
|
||||
newChapter.root.nodeAt(position.path).foreach { node =>
|
||||
sendTo(study, StudySocket.SetGlyphs(position, node.glyphs, sri))
|
||||
}
|
||||
|
@ -455,7 +455,7 @@ final class StudyApi(
|
|||
chapter.setGamebook(gamebook, position.path) match {
|
||||
case Some(newChapter) =>
|
||||
studyRepo.updateNow(study)
|
||||
chapterRepo.setGamebook(newChapter, position.path, gamebook) >>- {
|
||||
chapterRepo.setGamebook(gamebook)(newChapter, position.path) >>- {
|
||||
indexStudy(study)
|
||||
sendStudyEnters(study, userId)
|
||||
}
|
||||
|
@ -475,7 +475,7 @@ final class StudyApi(
|
|||
case Some((chapter, path)) =>
|
||||
studyRepo.updateNow(study)
|
||||
chapter.root.nodeAt(path) ?? { parent =>
|
||||
chapterRepo.setChildren(chapter, path, parent.children) >>- {
|
||||
chapterRepo.setChildren(parent.children)(chapter, path) >>- {
|
||||
sendStudyEnters(study, userId)
|
||||
sendTo(study, StudySocket.ReloadAll)
|
||||
}
|
||||
|
|
|
@ -81,9 +81,7 @@ final class StudyPager(
|
|||
def withChapters(studies: Seq[Study], nbChaptersPerStudy: Int): Fu[Seq[Study.WithChapters]] =
|
||||
chapterRepo.idNamesByStudyIds(studies.map(_.id), nbChaptersPerStudy) map { chapters =>
|
||||
studies.map { study =>
|
||||
Study.WithChapters(study, ~(chapters get study.id map {
|
||||
_ map (_.name)
|
||||
}))
|
||||
Study.WithChapters(study, (chapters get study.id) ?? (_ map (_.name)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue