<commit_before>package lila
package game

import chess.{ Color, Status }
import user.User

import com.novus.salat._
import com.novus.salat.dao._
import com.mongodb.casbah.MongoCollection
import com.mongodb.casbah.Imports._
import org.joda.time.DateTime
import org.scala_tools.time.Imports._

object Query {
  
  val all = DBObject()

  val rated: DBObject = DBObject("ra" -> true)

  val started: DBObject = ("s" $gte Status.Started.id)

  val playable: DBObject = ("s" $lt Status.Aborted.id)

  val mate: DBObject = DBObject("s" -> Status.Mate.id).pp

  val draw: DBObject = "s" $in List(Status.Draw.id, Status.Stalemate.id)

  val finished: DBObject = "s" $in List(Status.Mate.id, Status.Resign.id, Status.Outoftime.id, Status.Timeout.id)

  val notFinished: DBObject = "s" $lte Status.Started.id

  val frozen: DBObject = "s" $gte Status.Mate.id

  val popular: DBObject = "bm" $gt 0

  def clock(c: Boolean): DBObject = "c" $exists c

  def user(u: User): DBObject = DBObject("uids" -> u.id)

  def started(u: User): DBObject = user(u) ++ started

  def rated(u: User): DBObject = user(u) ++ rated

  def win(u: User): DBObject = DBObject("wid" -> u.id)

  def draw(u: User): DBObject = user(u) ++ draw

  def loss(u: User): DBObject = user(u) ++ finished ++ ("wid" $ne u.id)

  def notFinished(u: User): DBObject = user(u) ++ notFinished

  def opponents(u1: User, u2: User) = "uids" $all List(u1.id, u2.id)

  def turnsGt(nb: Int) = "t" $gt nb

  val sortCreated = DBObject("ca" -> -1)

  val sortPopular = DBObject("bm" -> -1)
}<commit_msg>use game3.uids index when looking for won games<commit_after>package lila
package game

import chess.{ Color, Status }
import user.User

import com.novus.salat._
import com.novus.salat.dao._
import com.mongodb.casbah.MongoCollection
import com.mongodb.casbah.Imports._
import org.joda.time.DateTime
import org.scala_tools.time.Imports._

object Query {
  
  val all = DBObject()

  val rated: DBObject = DBObject("ra" -> true)

  val started: DBObject = ("s" $gte Status.Started.id)

  val playable: DBObject = ("s" $lt Status.Aborted.id)

  val mate: DBObject = DBObject("s" -> Status.Mate.id)

  val draw: DBObject = "s" $in List(Status.Draw.id, Status.Stalemate.id)

  val finished: DBObject = "s" $in List(Status.Mate.id, Status.Resign.id, Status.Outoftime.id, Status.Timeout.id)

  val notFinished: DBObject = "s" $lte Status.Started.id

  val frozen: DBObject = "s" $gte Status.Mate.id

  val popular: DBObject = "bm" $gt 0

  def clock(c: Boolean): DBObject = "c" $exists c

  def user(u: User): DBObject = DBObject("uids" -> u.id)

  def started(u: User): DBObject = user(u) ++ started

  def rated(u: User): DBObject = user(u) ++ rated

  // use the uids index
  def win(u: User): DBObject = DBObject("uids" -> u.id, "wid" -> u.id)

  def draw(u: User): DBObject = user(u) ++ draw

  def loss(u: User): DBObject = user(u) ++ finished ++ ("wid" $ne u.id)

  def notFinished(u: User): DBObject = user(u) ++ notFinished

  def opponents(u1: User, u2: User) = "uids" $all List(u1.id, u2.id)

  def turnsGt(nb: Int) = "t" $gt nb

  val sortCreated = DBObject("ca" -> -1)

  val sortPopular = DBObject("bm" -> -1)
}
{'fraction_non_alphanumeric': 0.15545023696682464, 'fraction_numerical': 0.004739336492890996, 'mean_word_length': 3.725373134328358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5962144', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1188, 'n_words': 329}