From de339c4b85d42108bc3ab11f03f7babc77681e0c Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Mon, 22 Oct 2012 23:02:32 +0200 Subject: [PATCH] also remove pgn docs when removing games --- app/core/CoreEnv.scala | 1 + app/core/Titivate.scala | 4 +++- app/game/GameRepo.scala | 3 ++- app/game/PgnRepo.scala | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/core/CoreEnv.scala b/app/core/CoreEnv.scala index dae29660c35f..674164a24eb4 100644 --- a/app/core/CoreEnv.scala +++ b/app/core/CoreEnv.scala @@ -159,6 +159,7 @@ final class CoreEnv private (application: Application, val settings: Settings) { lazy val titivate = new lila.core.Titivate( gameRepo = game.gameRepo, + pgnRepo = game.pgnRepo, finisher = round.finisher, meddler = round.meddler, bookmarkApi = bookmark.api) diff --git a/app/core/Titivate.scala b/app/core/Titivate.scala index 02be0240ef5f..8a8845a64c90 100644 --- a/app/core/Titivate.scala +++ b/app/core/Titivate.scala @@ -1,7 +1,7 @@ package lila package core -import game.GameRepo +import game.{ GameRepo, PgnRepo } import round.{ Finisher, Meddler } import bookmark.BookmarkApi @@ -12,6 +12,7 @@ import scalaz.effects._ final class Titivate( gameRepo: GameRepo, + pgnRepo: PgnRepo, finisher: Finisher, meddler: Meddler, bookmarkApi: BookmarkApi) { @@ -33,6 +34,7 @@ final class Titivate( _ ← putStrLn("[titivate] Remove %d unplayed games" format ids.size) _ ← gameRepo removeIds ids _ ← bookmarkApi removeByGameIds ids + _ ← pgnRepo removeIds ids } yield () val cleanupNext: IO[Unit] = { diff --git a/app/game/GameRepo.scala b/app/game/GameRepo.scala index 06fbb0c29fea..f0e48e019109 100644 --- a/app/game/GameRepo.scala +++ b/app/game/GameRepo.scala @@ -145,11 +145,12 @@ final class GameRepo(collection: MongoCollection) ) } - // bookmarks should also be removed + // bookmarks and pgns should also be removed def remove(id: String): IO[Unit] = io { remove(idSelector(id)) } + // bookmarks and pgns should also be removed def removeIds(ids: List[String]): IO[Unit] = io { remove("_id" $in ids) } diff --git a/app/game/PgnRepo.scala b/app/game/PgnRepo.scala index 077d277c51f3..4c16066e409c 100644 --- a/app/game/PgnRepo.scala +++ b/app/game/PgnRepo.scala @@ -25,5 +25,9 @@ final class PgnRepo(collection: MongoCollection) { def unsafeGet(id: String): String = collection.findOne(idSelector(id)).flatMap(_.getAs[String]("p")) | "" + def removeIds(ids: List[String]): IO[Unit] = io { + collection.remove("_id" $in ids) + } + private def idSelector(id: String) = DBObject("_id" -> id) }