send more heavy reads to mongodb secondaries
parent
608eee8be5
commit
d5f3dad590
|
@ -49,7 +49,7 @@ final class CoachApi(
|
|||
|
||||
def listedWithUserList: Fu[List[Coach.WithUser]] =
|
||||
all.map(_.filter(_.isListed)) flatMap { coaches =>
|
||||
UserRepo.byIds(coaches.map(_.id.value)) map { users =>
|
||||
UserRepo.byIdsSecondary(coaches.map(_.id.value)) map { users =>
|
||||
coaches.flatMap { coach =>
|
||||
users find coach.is filter Granter(_.Coach) map { Coach.WithUser(coach, _) }
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@ trait CollExt { self: dsl with QueryBuilderExt =>
|
|||
def uno[D: BSONDocumentReader](selector: Bdoc): Fu[Option[D]] =
|
||||
coll.find(selector).uno[D]
|
||||
|
||||
def list[D: BSONDocumentReader](selector: Bdoc): Fu[List[D]] =
|
||||
coll.find(selector).list[D]()
|
||||
def list[D: BSONDocumentReader](selector: Bdoc, readPreference: ReadPreference = ReadPreference.primary): Fu[List[D]] =
|
||||
coll.find(selector).list[D](readPreference = readPreference)
|
||||
|
||||
def list[D: BSONDocumentReader](selector: Bdoc, max: Int): Fu[List[D]] =
|
||||
coll.find(selector).list[D](max)
|
||||
def list[D: BSONDocumentReader](selector: Bdoc, limit: Int): Fu[List[D]] =
|
||||
coll.find(selector).list[D](limit = limit)
|
||||
|
||||
def byId[D: BSONDocumentReader, I: BSONValueWriter](id: I): Fu[Option[D]] =
|
||||
uno[D]($id(id))
|
||||
|
@ -26,11 +26,11 @@ trait CollExt { self: dsl with QueryBuilderExt =>
|
|||
|
||||
def byId[D: BSONDocumentReader](id: Int): Fu[Option[D]] = uno[D]($id(id))
|
||||
|
||||
def byIds[D: BSONDocumentReader, I: BSONValueWriter](ids: Iterable[I]): Fu[List[D]] =
|
||||
def byIds[D: BSONDocumentReader, I: BSONValueWriter](ids: Iterable[I], readPreference: ReadPreference): Fu[List[D]] =
|
||||
list[D]($inIds(ids))
|
||||
|
||||
def byIds[D: BSONDocumentReader](ids: Iterable[String]): Fu[List[D]] =
|
||||
byIds[D, String](ids)
|
||||
def byIds[D: BSONDocumentReader](ids: Iterable[String], readPreference: ReadPreference = ReadPreference.primary): Fu[List[D]] =
|
||||
byIds[D, String](ids, readPreference)
|
||||
|
||||
def countSel(
|
||||
selector: Bdoc,
|
||||
|
@ -54,8 +54,8 @@ trait CollExt { self: dsl with QueryBuilderExt =>
|
|||
// def byOrderedIds[A <: Identified[String]: TubeInColl](ids: Iterable[String]): Fu[List[A]] =
|
||||
// byOrderedIds[String, A](ids)
|
||||
|
||||
def optionsByOrderedIds[D: BSONDocumentReader, I: BSONValueWriter](ids: Iterable[I])(docId: D => I): Fu[List[Option[D]]] =
|
||||
byIds[D, I](ids) map { docs =>
|
||||
def optionsByOrderedIds[D: BSONDocumentReader, I: BSONValueWriter](ids: Iterable[I], readPreference: ReadPreference = ReadPreference.primary)(docId: D => I): Fu[List[Option[D]]] =
|
||||
byIds[D, I](ids, readPreference) map { docs =>
|
||||
val docsMap = docs.map(u => docId(u) -> u).toMap
|
||||
ids.map(docsMap.get).toList
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ trait QueryBuilderExt { self: dsl =>
|
|||
|
||||
def list[A: BSONDocumentReader](limit: Int): Fu[List[A]] = list[A](limit.some)
|
||||
|
||||
def list[A: BSONDocumentReader](): Fu[List[A]] = list[A](none)
|
||||
def list[A: BSONDocumentReader](readPreference: ReadPreference = ReadPreference.primary): Fu[List[A]] = list[A](none)
|
||||
|
||||
// like one, but with stopOnError defaulting to false
|
||||
def uno[A: BSONDocumentReader]: Fu[Option[A]] = uno[A](ReadPreference.primary)
|
||||
|
|
|
@ -34,7 +34,8 @@ object Team {
|
|||
|
||||
def contains(teamId: ID) = value contains teamId
|
||||
|
||||
def toList = if (value.isEmpty) Nil else value.split(IdsStr.separator).toList
|
||||
def toArray: Array[String] = value.split(IdsStr.separator)
|
||||
def toList = if (value.isEmpty) Nil else toArray.toList
|
||||
}
|
||||
|
||||
object IdsStr {
|
||||
|
|
|
@ -57,7 +57,7 @@ final class TeamApi(
|
|||
}
|
||||
|
||||
def mine(me: User): Fu[List[Team]] =
|
||||
cached teamIds me.id dmap (_.toList) flatMap coll.team.byIds[Team]
|
||||
cached teamIds me.id flatMap { ids => coll.team.byIds[Team](ids.toArray) }
|
||||
|
||||
def hasTeams(me: User): Fu[Boolean] = cached.teamIds(me.id).map(_.value.nonEmpty)
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ private[timeline] final class Push(
|
|||
case Users(ids) => fuccess(ids)
|
||||
case Followers(id) => getFollowerIds(id)
|
||||
case Friends(id) => getFriendIds(id)
|
||||
case StaffFriends(id) => getFriendIds(id) flatMap UserRepo.byIds map {
|
||||
case StaffFriends(id) => getFriendIds(id) flatMap UserRepo.byIdsSecondary map {
|
||||
_ filter Granter(_.StaffForum) map (_.id)
|
||||
}
|
||||
case ExceptUser(_) => fuccess(Nil)
|
||||
|
|
|
@ -31,6 +31,8 @@ object UserRepo {
|
|||
|
||||
def byIds(ids: Iterable[ID]): Fu[List[User]] = coll.byIds[User](ids)
|
||||
|
||||
def byIdsSecondary(ids: Iterable[ID]): Fu[List[User]] = coll.byIds[User](ids, ReadPreference.secondaryPreferred)
|
||||
|
||||
def byEmail(email: String): Fu[Option[User]] = coll.uno[User]($doc(F.email -> email))
|
||||
|
||||
def idByEmail(email: String): Fu[Option[String]] =
|
||||
|
@ -48,7 +50,7 @@ object UserRepo {
|
|||
coll.byOrderedIds[User, User.ID](ids)(_.id)
|
||||
|
||||
def enabledByIds(ids: Iterable[ID]): Fu[List[User]] =
|
||||
coll.list[User](enabledSelect ++ $inIds(ids))
|
||||
coll.list[User](enabledSelect ++ $inIds(ids), ReadPreference.secondaryPreferred)
|
||||
|
||||
def enabledById(id: ID): Fu[Option[User]] =
|
||||
coll.uno[User](enabledSelect ++ $id(id))
|
||||
|
|
Loading…
Reference in New Issue