diff --git a/bin/mongodb/play21.js b/bin/mongodb/play21.js index 6b934f60f87d..27a8e3caddbc 100644 --- a/bin/mongodb/play21.js +++ b/bin/mongodb/play21.js @@ -76,8 +76,9 @@ print('index forum post authors'); db.f_post.ensureIndex({userId:1}) print('create timeline_entry collection'); -db.createCollection('timeline_entry'); +db.createCollection("timeline_entry",{capped:true,size:50000000}) db.timeline_entry.ensureIndex({user:1, date: -1}); +db.timeline_entry.ensureIndex({type:1, date: -1}); // print("Reset lobby_room"); // db.lobby_room.drop(); diff --git a/modules/forum/src/main/PostApi.scala b/modules/forum/src/main/PostApi.scala index 575b7b727dcc..3f81f02ed8df 100644 --- a/modules/forum/src/main/PostApi.scala +++ b/modules/forum/src/main/PostApi.scala @@ -8,7 +8,7 @@ import lila.common.paginator._ import lila.db.api._ import lila.db.Implicits._ import lila.db.paginator._ -import lila.hub.actorApi.timeline.{ MakeEntry, ForumPost } +import lila.hub.actorApi.timeline.{ ShareEntry, ForumPost } import lila.hub.ActorLazyRef import lila.mod.ModlogApi import lila.user.{ User, Context } @@ -41,7 +41,7 @@ final class PostApi( (indexer ! InsertPost(post)) >> (env.recent.invalidate inject post) >>- (ctx.userId ?? { userId ⇒ - relationActor ! MakeEntry( + relationActor ! ShareEntry( userId, ForumPost(userId, categ.id, topic.slug, topic.name, lastPageOf(topic withPost post), post.number) ) diff --git a/modules/hub/src/main/actorApi.scala b/modules/hub/src/main/actorApi.scala index f589f39cdc84..286c4ba7bf1a 100644 --- a/modules/hub/src/main/actorApi.scala +++ b/modules/hub/src/main/actorApi.scala @@ -60,7 +60,8 @@ package timeline { implicit val forumPostFormat = Json.format[ForumPost] } - case class MakeEntry(user: String, data: Atom) + case class ShareEntry(user: String, data: Atom) + case class MakeEntry(users: List[String], data: Atom) } package game { diff --git a/modules/relation/src/main/RelationActor.scala b/modules/relation/src/main/RelationActor.scala index 742af6ba2737..f28da2c358f0 100644 --- a/modules/relation/src/main/RelationActor.scala +++ b/modules/relation/src/main/RelationActor.scala @@ -6,7 +6,7 @@ import akka.pattern.{ ask, pipe } import actorApi._ import lila.hub.actorApi.relation._ import lila.hub.actorApi.SendTos -import lila.hub.actorApi.timeline.MakeEntry +import lila.hub.actorApi.timeline.{ MakeEntry, ShareEntry } import lila.hub.ActorLazyRef private[relation] final class RelationActor( @@ -18,11 +18,9 @@ private[relation] final class RelationActor( def receive = { - case MakeEntry(userId, data) ⇒ getFriendIds(userId) foreach { ids ⇒ - ids foreach { id ⇒ - timelinePush ! MakeEntry(id, data) - } - } + case ShareEntry(userId, data) ⇒ getFriendIds(userId) map { ids ⇒ + MakeEntry(ids.toList, data) + } pipeTo timelinePush.ref // rarely called // return a list of usernames, followers, following and online diff --git a/modules/relation/src/main/RelationApi.scala b/modules/relation/src/main/RelationApi.scala index 92863c681bae..af39c9f2fb1b 100644 --- a/modules/relation/src/main/RelationApi.scala +++ b/modules/relation/src/main/RelationApi.scala @@ -3,7 +3,7 @@ package lila.relation import lila.db.api._ import lila.db.Implicits._ import lila.game.GameRepo -import lila.hub.actorApi.timeline.{ MakeEntry, Follow ⇒ FollowUser, FollowYou } +import lila.hub.actorApi.timeline.{ MakeEntry, ShareEntry, Follow ⇒ FollowUser, FollowYou } import lila.hub.ActorLazyRef import lila.user.tube.userTube import lila.user.{ User, UserRepo } @@ -35,8 +35,8 @@ final class RelationApi( case Some(Follow) ⇒ fufail("Already following") case _ ⇒ RelationRepo.follow(u1, u2) >> cached.invalidate(u1, u2) >>- - (timelinePush ! MakeEntry(u2, FollowYou(u1))) >>- - (relationActor ! MakeEntry(u1, FollowUser(u1, u2))) + (timelinePush ! MakeEntry(List(u2), FollowYou(u1))) >>- + (relationActor ! ShareEntry(u1, FollowUser(u1, u2))) } def block(u1: ID, u2: ID): Funit = diff --git a/modules/team/src/main/TeamApi.scala b/modules/team/src/main/TeamApi.scala index eb2a712e3ee7..6a900468d94d 100644 --- a/modules/team/src/main/TeamApi.scala +++ b/modules/team/src/main/TeamApi.scala @@ -5,7 +5,7 @@ import org.scala_tools.time.Imports._ import actorApi._ import lila.db.api._ import lila.hub.actorApi.forum.MakeTeam -import lila.hub.actorApi.timeline.{ MakeEntry, TeamJoin, TeamCreate } +import lila.hub.actorApi.timeline.{ ShareEntry, TeamJoin, TeamCreate } import lila.hub.ActorLazyRef import lila.user.tube.userTube import lila.user.{ User, Context } @@ -37,7 +37,7 @@ final class TeamApi( (cached.teamIds remove me.id) >>- (forum ! MakeTeam(team.id, team.name)) >>- (indexer ! InsertTeam(team)) >>- - (relationActor ! MakeEntry(me.id, TeamCreate(me.id, team.id))) inject team + (relationActor ! ShareEntry(me.id, TeamCreate(me.id, team.id))) inject team } def update(team: Team, edit: TeamEdit, me: User): Funit = edit.trim |> { e ⇒ @@ -114,7 +114,7 @@ final class TeamApi( MemberRepo.add(team.id, userId) >> TeamRepo.incMembers(team.id, +1) >> (cached.teamIds remove userId) >>- - (relationActor ! MakeEntry(userId, TeamJoin(userId, team.id))) + (relationActor ! ShareEntry(userId, TeamJoin(userId, team.id))) } } diff --git a/modules/timeline/src/main/Entry.scala b/modules/timeline/src/main/Entry.scala index 4266c200fb24..ede54da80729 100644 --- a/modules/timeline/src/main/Entry.scala +++ b/modules/timeline/src/main/Entry.scala @@ -8,17 +8,14 @@ import lila.hub.actorApi.timeline._ import lila.hub.actorApi.timeline.atomFormat._ case class Entry( - user: String, + users: List[String], typ: String, data: JsObject, date: DateTime) { import Entry._ - def similarTo(other: Entry) = - (user == other.user) && - (typ == other.typ) && - (data == other.data) + def similarTo(other: Entry) = typ == other.typ && data == other.data def decode: Option[Atom] = (typ match { case "follow" ⇒ Json.fromJson[Follow](data) @@ -31,14 +28,14 @@ case class Entry( object Entry { - private[timeline] def make(user: String, data: Atom): Option[Entry] = (data match { + private[timeline] def make(users: List[String], data: Atom): Option[Entry] = (data match { case d: Follow ⇒ "follow" -> Json.toJson(d) case d: FollowYou ⇒ "follow-you" -> Json.toJson(d) case d: TeamJoin ⇒ "team-join" -> Json.toJson(d) case d: TeamCreate ⇒ "team-create" -> Json.toJson(d) case d: ForumPost ⇒ "forum-post" -> Json.toJson(d) }) match { - case (typ, json) ⇒ json.asOpt[JsObject] map { new Entry(user, typ, _, DateTime.now) } + case (typ, json) ⇒ json.asOpt[JsObject] map { new Entry(users, typ, _, DateTime.now) } } import lila.db.Tube diff --git a/modules/timeline/src/main/Push.scala b/modules/timeline/src/main/Push.scala index d63c396d2a2f..f92cdfdfd4ea 100644 --- a/modules/timeline/src/main/Push.scala +++ b/modules/timeline/src/main/Push.scala @@ -17,20 +17,21 @@ private[timeline] final class Push( renderer: lila.hub.ActorLazyRef) extends Actor { def receive = { - case MakeEntry(user, data) ⇒ makeEntry(user, data) foreach { entry ⇒ - lobbySocket.ref ! ReloadTimeline(user) - } + case MakeEntry(users, data) ⇒ makeEntry(users, data) >>- + (users foreach { u ⇒ + lobbySocket.ref ! ReloadTimeline(u) + }) } - private def makeEntry(user: String, data: Atom): Fu[Entry] = - Entry.make(user, data).fold( + private def makeEntry(users: List[String], data: Atom): Fu[Entry] = + Entry.make(users, data).fold( fufail[Entry]("[timeline] invalid entry data " + data) ) { entry ⇒ - $find(Json.obj("user" -> user, "date" -> $gt($date(DateTime.now - 1.hour)))) flatMap { entries ⇒ - entries exists (_ similarTo entry) fold ( - fufail[Entry]("[timeline] a similar entry already exists"), - $insert(entry) inject entry - ) + $find(Json.obj("typ" -> entry.typ, "date" -> $gt($date(DateTime.now - 1.hour)))) flatMap { entries ⇒ + entries exists (_ similarTo entry) fold ( + fufail[Entry]("[timeline] a similar entry already exists"), + $insert(entry) inject entry + ) + } } - } } diff --git a/todo b/todo index 1766a4f1119a..ffcafd3b3931 100644 --- a/todo +++ b/todo @@ -71,7 +71,6 @@ takeback/enpassant glitch http://en.lichess.org/forum/lichess-feedback/i-found-a show teams in user mini badges for top players in ELO and number of games use jquery.timeago everywhere -sort imports DEPLOY p21 ----------