Skip to content

Commit

Permalink
mongodb count -> size optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Oct 25, 2012
1 parent d026e46 commit 922dac5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/analyse/AnalysisRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ final class AnalysisRepo(val collection: MongoCollection) {
def doneById(id: String): IO[Option[Analysis]] = byId(id) map { _ filter (_.done) }

def isDone(id: String): IO[Boolean] = io {
collection.count(DBObject("_id" -> id, "done" -> true)) > 0
collection.find(DBObject("_id" -> id, "done" -> true)).limit(1).size == 1
}

def userInProgress(uid: String): IO[Boolean] = io {
collection.count(
("fail" $exists false) ++
DBObject("uid" -> uid, "done" -> false)
) > 0
collection.find(
("fail" $exists false) ++ DBObject("uid" -> uid, "done" -> false)
).limit(1).size > 0
}
}

0 comments on commit 922dac5

Please sign in to comment.