use events rather than polling to reload homepage recent forum posts

pull/83/head
Thibault Duplessis 2013-10-22 22:53:20 +02:00
parent e6b9f0643c
commit b7c517a386
9 changed files with 48 additions and 43 deletions

View File

@ -147,7 +147,7 @@ Which yields a game list of type `IO[List[Game]]`
Search
------
Searching in mongodb just does not work, so the [search engine](http://en.lichess.org/games/search) is powered by elasticsearch. When a game is finished, its ID is stored in the `index_queue` mongodb collection, then a daemon periodically batch inserts them into the elasticsearch index.
Searching in mongodb just does not work, so the [search engine](http://en.lichess.org/games/search) is powered by elasticsearch.
Monitoring
----------

View File

@ -51,9 +51,8 @@ package captcha {
}
package lobby {
case class SysTalk(txt: String)
case class UnTalk(r: scala.util.matching.Regex)
case class ReloadTournaments(html: String)
case object NewForumPost
}
package timeline {

View File

@ -2,20 +2,20 @@ package lila.lobby
import scala.concurrent.duration._
import actorApi._
import akka.actor._
import akka.pattern.ask
import makeTimeout.short
import play.api.libs.iteratee._
import play.api.libs.json._
import play.api.templates.Html
import actorApi._
import lila.game.actorApi._
import lila.hub.actorApi.lobby._
import lila.hub.actorApi.router.{ Homepage, Player }
import lila.hub.actorApi.timeline._
import lila.socket.actorApi.{ Connected _, _ }
import lila.socket.{ SocketActor, History, Historical }
import makeTimeout.short
private[lobby] final class Socket(
val history: History,
@ -40,6 +40,8 @@ private[lobby] final class Socket(
case ReloadTournaments(html) notifyTournaments(html)
case NewForumPost notifyAll("reload_forum")
case GameEntryView(rendered) notifyVersion("game_entry", rendered)
case ReloadTimeline(user) sendTo(user, makeMessage("reload_timeline", JsNull))

View File

@ -4,6 +4,8 @@ import play.api.libs.json._
private[socket] trait Socket {
def makeMessage[A: Writes](t: String, data: A) =
def makeMessage[A: Writes](t: String, data: A): JsObject =
Json.obj("t" -> t, "d" -> data)
def makeMessage(t: String): JsObject = Json.obj("t" -> t)
}

View File

@ -58,7 +58,14 @@ abstract class SocketActor[M <: SocketMember](uidTtl: Duration) extends Socket w
}
def notifyAll[A: Writes](t: String, data: A) {
val msg = makeMessage(t, data)
notifyAll(makeMessage(t, data))
}
def notifyAll(t: String) {
notifyAll(makeMessage(t))
}
def notifyAll(msg: JsObject) {
members.values.foreach(_.channel push msg)
}

View File

@ -8,8 +8,9 @@ import play.api.libs.json._
import play.api.templates.Html
import lila.db.api._
import lila.hub.actorApi.lobby.NewForumPost
import lila.hub.actorApi.timeline.propagation._
import lila.hub.actorApi.timeline.{ Propagate, Atom, ReloadTimeline }
import lila.hub.actorApi.timeline.{ Propagate, Atom, ForumPost, ReloadTimeline }
import lila.security.Granter
import lila.user.UserRepo
import makeTimeout.short
@ -22,11 +23,17 @@ private[timeline] final class Push(
def receive = {
case Propagate(data, propagations) propagate(propagations) foreach { users
if (users.nonEmpty) makeEntry(users, data) >>-
(users foreach { u
lobbySocket ! ReloadTimeline(u)
})
case Propagate(data, propagations) {
data match {
case _: ForumPost lobbySocket ! NewForumPost
case _
}
propagate(propagations) foreach { users
if (users.nonEmpty) makeEntry(users, data) >>-
(users foreach { u
lobbySocket ! ReloadTimeline(u)
})
}
}
}

View File

@ -11,7 +11,7 @@ import actorApi._
import chess.{ Mode, Variant }
import lila.db.api._
import lila.game.{ Game, GameRepo }
import lila.hub.actorApi.lobby.{ SysTalk, UnTalk, ReloadTournaments }
import lila.hub.actorApi.lobby.ReloadTournaments
import lila.hub.actorApi.map.Tell
import lila.hub.actorApi.router.Tourney
import lila.round.actorApi.round.{ AbortForce, ResignColor }
@ -54,8 +54,7 @@ private[tournament] final class TournamentApi(
$insert(created) >>-
(withdrawIds foreach socketReload) >>-
reloadSiteSocket >>-
lobbyReload >>-
sendLobbyMessage(created) inject created
lobbyReload inject created
}
def startIfReady(created: Created): Option[Funit] = created.startIfReady map doStart
@ -74,8 +73,7 @@ private[tournament] final class TournamentApi(
$remove(created) >>
$remove.byId[Room](created.id) >>-
reloadSiteSocket >>-
lobbyReload >>-
(lobby ! UnTalk("%s tournament created".format(created.name).r))
lobbyReload
}
def finish(started: Started): Fu[Tournament] = started.readyToFinish.fold({
@ -154,18 +152,6 @@ private[tournament] final class TournamentApi(
site ! SendToFlag("tournament", reloadMessage)
}
private def sendLobbyMessage(tour: Created) {
router ? Tourney(tour.id) map {
case url: String SysTalk(
"""<a href="%s">%s tournament created</a>""".format(url, tour.name)
)
} pipeToSelection lobby
}
private def removeLobbyMessage(tour: Created) {
lobby ! UnTalk("%s tournament created".format(tour.name).r)
}
private def sendTo(tourId: String, msg: Any) {
socketHub ! Tell(tourId, msg)
}

View File

@ -382,7 +382,6 @@ var storage = {
onProduction: /.+\.lichess\.org/.test(document.domain)
};
// lichess.socketDefaults.options.debug = !lichess.onProduction;
// lichess.socketDefaults.options.debug = true;
lichess.hasToReload = false;
lichess.reload = function() {
@ -2152,15 +2151,6 @@ var storage = {
$bot.on("click", "tr", function() {
location.href = $(this).find('a.watch').attr("href");
});
setInterval(function() {
$.ajax($newposts.data('url'), {
timeout: 10000,
success: function(data) {
$newpostsinner.find('ol').html(data).end().scrollTop(0);
$('body').trigger('lichess.content_loaded');
}
});
}, 120 * 1000);
function resizeTimeline() {
var max = $('#lichess').offset().top + 516;
@ -2202,7 +2192,8 @@ var storage = {
$.lichessOpeningPreventClicks();
location.href = 'http://' + location.hostname + '/' + e;
},
tournaments: reloadTournaments
tournaments: reloadTournaments,
reload_forum: reloadForum
},
options: {
name: "lobby"
@ -2213,6 +2204,15 @@ var storage = {
$("table.tournaments tbody").html(data);
}
function reloadForum() {
$.ajax($newposts.data('url'), {
success: function(data) {
$newpostsinner.find('ol').html(data).end().scrollTop(0);
$('body').trigger('lichess.content_loaded');
}
});
}
function changeFeatured(html) {
$('#featured_game').html(html);
$('body').trigger('lichess.content_loaded');

6
todo
View File

@ -75,6 +75,8 @@ people page = trends by day, week, month. user achievments?
user options: sounds, sound choice
user stats: http://en.lichess.org/forum/lichess-feedback/feature-request-extended-stats
forum improvements http://en.lichess.org/forum/lichess-feedback/suggestions-for-the-forum#1
real tournaments (round robin/swiss) (hellball)
real tournaments (swiss first, then round robin) (hellball) see challonge.com
option to disallow takebacks http://en.lichess.org/forum/lichess-feedback/takeback-request-abuse
reload forum/recent on event, not polling
search users from tablet http://en.lichess.org/forum/lichess-feedback/people---search
spectator tooltips
disable reporting when no one is watching