throttle challenges socket messages
parent
bcd0e8da32
commit
4dec6a6712
|
@ -148,22 +148,26 @@ final class ChallengeApi(
|
|||
|
||||
private def uncacheAndNotify(c: Challenge): Unit = {
|
||||
c.destUserId ?? countInFor.invalidate
|
||||
c.destUserId ?? notify
|
||||
c.challengerUserId ?? notify
|
||||
c.destUserId ?? notifyUser.apply
|
||||
c.challengerUserId ?? notifyUser.apply
|
||||
socketReload(c.id)
|
||||
}
|
||||
|
||||
private def socketReload(id: Challenge.ID): Unit =
|
||||
socket.foreach(_ reload id)
|
||||
|
||||
private def notify(userId: User.ID): Funit =
|
||||
for {
|
||||
all <- allFor(userId)
|
||||
lang <- userRepo langOf userId map I18nLangPicker.byStrOrDefault
|
||||
} yield Bus.publish(
|
||||
SendTo(userId, lila.socket.Socket.makeMessage("challenges", jsonView(all)(lang))),
|
||||
"socketUsers"
|
||||
)
|
||||
private object notifyUser {
|
||||
private val throttler = new lila.hub.EarlyMultiThrottler(logger)
|
||||
def apply(userId: User.ID): Unit = throttler(userId, 2.seconds) {
|
||||
for {
|
||||
all <- allFor(userId)
|
||||
lang <- userRepo langOf userId map I18nLangPicker.byStrOrDefault
|
||||
} yield Bus.publish(
|
||||
SendTo(userId, lila.socket.Socket.makeMessage("challenges", jsonView(all)(lang))),
|
||||
"socketUsers"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// work around circular dependency
|
||||
private var socket: Option[ChallengeSocket] = None
|
||||
|
|
|
@ -5,4 +5,6 @@ import org.joda.time.DateTime
|
|||
package object challenge extends PackageObject {
|
||||
|
||||
private[challenge] def inTwoWeeks = DateTime.now plusWeeks 2
|
||||
|
||||
private[challenge] val logger = lila log "challenge"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue