Skip to content

Commit

Permalink
also remove pgn docs when removing games
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Oct 22, 2012
1 parent bf95c4d commit de339c4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/core/CoreEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion app/core/Titivate.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package lila
package core

import game.GameRepo
import game.{ GameRepo, PgnRepo }
import round.{ Finisher, Meddler }
import bookmark.BookmarkApi

Expand All @@ -12,6 +12,7 @@ import scalaz.effects._

final class Titivate(
gameRepo: GameRepo,
pgnRepo: PgnRepo,
finisher: Finisher,
meddler: Meddler,
bookmarkApi: BookmarkApi) {
Expand All @@ -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] = {
Expand Down
3 changes: 2 additions & 1 deletion app/game/GameRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions app/game/PgnRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit de339c4

Please sign in to comment.