don't load forum participants' usernames into the light user cache

This commit is contained in:
Thibault Duplessis 2017-01-29 15:56:03 +01:00
parent c1ae809f6a
commit 7ad63d5037
3 changed files with 6 additions and 10 deletions

View file

@ -77,10 +77,10 @@ object ForumTopic extends LilaController with ForumController {
/**
* Returns a list of the usernames of people participating in a forum topic conversation
*/
def participants(topicId: String) = Auth { implicit ctx => me =>
postApi.userIds(topicId) map { ids =>
val usernames = Env.user.lightUserApi.getList(ids.sorted).map(_.name)
Ok(Json.toJson(usernames))
}
def participants(topicId: String) = Auth { implicit ctx => _ =>
for {
userIds <- postApi userIds topicId
usernames <- lila.user.UserRepo usernamesByIds userIds
} yield Ok(Json.toJson(usernames.sorted))
}
}

View file

@ -21,10 +21,6 @@ final class LightUserApi(coll: Coll)(implicit system: akka.actor.ActorSystem) {
def preloadMany = cache preloadMany _
def preloadUser(user: User) = cache.setOneIfAbsent(user.id, user.light.some)
def getList(ids: List[String]): List[LightUser] = ids flatMap sync
def usernameList(ids: List[String]): List[String] = getList(ids).map(_.name)
private val cache = new Syncache[String, Option[LightUser]](
name = "user.light",
compute = id => coll.find($id(id), projection).uno[LightUser],

View file

@ -85,7 +85,7 @@ object UserRepo {
coll.primitiveOne[User.ID]($id(id), F.username)
def usernamesByIds(ids: List[ID]) =
coll.distinct[User.ID, List](F.username, $inIds(ids).some)
coll.distinct[String, List](F.username, $inIds(ids).some)
def orderByGameCount(u1: User.ID, u2: User.ID): Fu[Option[(User.ID, User.ID)]] = {
coll.find(