preload report users

This commit is contained in:
Thibault Duplessis 2017-01-26 13:30:16 +01:00
parent 1b85c61dce
commit 6f2d947a37
3 changed files with 18 additions and 13 deletions

View file

@ -21,12 +21,11 @@ object Report extends LilaController {
renderList(reason)
}
private def renderList(reason: String)(implicit ctx: Context) =
api.unprocessedAndRecentWithFilter(50, Reason(reason)) flatMap { reports =>
api.countUnprocesssedByReasons map { counts =>
Ok(html.report.list(reports, reason, counts))
}
}
private def renderList(reason: String)(implicit ctx: Context) = for {
reports <- api.unprocessedAndRecentWithFilter(50, Reason(reason))
counts <- api.countUnprocesssedByReasons
_ <- Env.user.lightUserApi preloadMany reports.flatMap(_.userIds)
} yield Ok(html.report.list(reports, reason, counts))
def process(id: String) = Secure(_.SeeReport) { implicit ctx => me =>
api.process(id, me) inject Redirect(routes.Report.list)

View file

@ -41,6 +41,8 @@ case class Report(
def unprocessed = processedBy.isEmpty
def processed = processedBy.isDefined
def userIds = List(user, createdBy)
lazy val realReason: Reason = Reason byKey reason
}
@ -59,6 +61,8 @@ object Report {
def user = withUser.user
def hasLichessNote = notes.exists(_.from == "lichess")
def hasIrwinNote = notes.exists(_.from == "irwin")
def userIds = report.userIds ::: notes.flatMap(_.userIds)
}
case class ByAndAbout(by: List[Report], about: List[Report])

View file

@ -5,13 +5,15 @@ import org.joda.time.DateTime
import reactivemongo.api.ReadPreference
case class Note(
_id: String,
from: String,
to: String,
text: String,
troll: Boolean,
mod: Boolean,
date: DateTime)
_id: String,
from: String,
to: String,
text: String,
troll: Boolean,
mod: Boolean,
date: DateTime) {
def userIds = List(from, to)
}
case class UserNotes(user: User, notes: List[Note])