preload student light users
This commit is contained in:
parent
2d34ba44ee
commit
496e11e56e
|
@ -45,11 +45,15 @@ final class Clas(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def preloadStudentUsers(students: List[lila.clas.Student.WithUser]): Unit =
|
||||||
|
env.user.lightUserApi.preloadUsers(students.map(_.user))
|
||||||
|
|
||||||
def show(id: String) = Auth { implicit ctx => me =>
|
def show(id: String) = Auth { implicit ctx => me =>
|
||||||
isGranted(_.Teacher).??(env.clas.api.clas.isTeacherOf(me, lila.clas.Clas.Id(id))) flatMap {
|
isGranted(_.Teacher).??(env.clas.api.clas.isTeacherOf(me, lila.clas.Clas.Id(id))) flatMap {
|
||||||
case true =>
|
case true =>
|
||||||
WithClass(me, id) { _ => clas =>
|
WithClass(me, id) { _ => clas =>
|
||||||
env.clas.api.student.allOfWithUsers(clas) map { students =>
|
env.clas.api.student.allOfWithUsers(clas) map { students =>
|
||||||
|
preloadStudentUsers(students)
|
||||||
views.html.clas.clas.showToTeacher(clas, students)
|
views.html.clas.clas.showToTeacher(clas, students)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,9 +61,10 @@ final class Clas(
|
||||||
env.clas.api.clas.byId(lila.clas.Clas.Id(id)) flatMap {
|
env.clas.api.clas.byId(lila.clas.Clas.Id(id)) flatMap {
|
||||||
_ ?? { clas =>
|
_ ?? { clas =>
|
||||||
env.clas.api.student.activeOfWithUsers(clas) flatMap { students =>
|
env.clas.api.student.activeOfWithUsers(clas) flatMap { students =>
|
||||||
if (students.exists(_.student is me))
|
if (students.exists(_.student is me)) {
|
||||||
|
preloadStudentUsers(students)
|
||||||
Ok(views.html.clas.clas.showToStudent(clas, students)).fuccess
|
Ok(views.html.clas.clas.showToStudent(clas, students)).fuccess
|
||||||
else notFound
|
} else notFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,10 @@ final class LightUserApi(
|
||||||
|
|
||||||
def invalidate = cache invalidate _
|
def invalidate = cache invalidate _
|
||||||
|
|
||||||
def preloadOne = cache preloadOne _
|
def preloadOne = cache preloadOne _
|
||||||
def preloadMany = cache preloadMany _
|
def preloadMany = cache preloadMany _
|
||||||
def preloadUser(user: User) = cache.set(user.id, user.light.some)
|
def preloadUser(user: User) = cache.set(user.id, user.light.some)
|
||||||
|
def preloadUsers(users: Seq[User]) = users.foreach(preloadUser)
|
||||||
|
|
||||||
private val cache = cacheApi.sync[User.ID, Option[LightUser]](
|
private val cache = cacheApi.sync[User.ID, Option[LightUser]](
|
||||||
name = "user.light",
|
name = "user.light",
|
||||||
|
|
Loading…
Reference in a new issue