<commit_before>package lila.forum

import lila.db.dsl._

object TopicRepo extends TopicRepo(false) {

  def apply(troll: Boolean): TopicRepo = troll.fold(TopicRepoTroll, TopicRepo)
}

object TopicRepoTroll extends TopicRepo(true)

sealed abstract class TopicRepo(troll: Boolean) {

  import BSONHandlers.TopicBSONHandler

  // dirty
  private val coll = Env.current.topicColl

  private val trollFilter = troll.fold($empty, $doc("troll" -> false))
  private val notStickyQuery = $doc("sticky" $ne true)

  def close(id: String, value: Boolean): Funit =
    coll.updateField($id(id), "closed", value).void

  def hide(id: String, value: Boolean): Funit =
    coll.updateField($id(id), "hidden", value).void

  def sticky(id: String, value: Boolean): Funit =
    coll.updateField($id(id), "sticky", value).void

  def byCateg(categ: Categ): Fu[List[Topic]] =
    coll.list[Topic](byCategQuery(categ))

  def byTree(categSlug: String, slug: String): Fu[Option[Topic]] =
    coll.uno[Topic]($doc("categId" -> categSlug, "slug" -> slug) ++ trollFilter)

  def stickyByCateg(categ: Categ): Fu[List[Topic]] =
    coll.list[Topic](byCategQuery(categ) ++ byStickyQuery())

  def nextSlug(categ: Categ, name: String, it: Int = 1): Fu[String] = {
    val slug = Topic.nameToId(name) + ~(it != 1).option("-" + it)
    // also take troll topic into accounts
    TopicRepoTroll.byTree(categ.slug, slug) flatMap {
      _.isDefined.fold(
        nextSlug(categ, name, it + 1),
        fuccess(slug)
      )
    }
  }

  def incViews(topic: Topic) =
    coll.incFieldUnchecked($id(topic.id), "views")

  def byCategQuery(categ: Categ) = $doc("categId" -> categ.slug) ++ trollFilter
  def byCategNotStickyQuery(categ: Categ) = byCategQuery(categ) ++ notStickyQuery
  def byStickyQuery() = $doc("sticky" -> true)
}<commit_msg>byStickyQuery doesn't need to be a function<commit_after>package lila.forum

import lila.db.dsl._

object TopicRepo extends TopicRepo(false) {

  def apply(troll: Boolean): TopicRepo = troll.fold(TopicRepoTroll, TopicRepo)
}

object TopicRepoTroll extends TopicRepo(true)

sealed abstract class TopicRepo(troll: Boolean) {

  import BSONHandlers.TopicBSONHandler

  // dirty
  private val coll = Env.current.topicColl

  private val trollFilter = troll.fold($empty, $doc("troll" -> false))
  private val notStickyQuery = $doc("sticky" $ne true)
  private val stickyQuery = $doc("sticky" -> true)

  def close(id: String, value: Boolean): Funit =
    coll.updateField($id(id), "closed", value).void

  def hide(id: String, value: Boolean): Funit =
    coll.updateField($id(id), "hidden", value).void

  def sticky(id: String, value: Boolean): Funit =
    coll.updateField($id(id), "sticky", value).void

  def byCateg(categ: Categ): Fu[List[Topic]] =
    coll.list[Topic](byCategQuery(categ))

  def byTree(categSlug: String, slug: String): Fu[Option[Topic]] =
    coll.uno[Topic]($doc("categId" -> categSlug, "slug" -> slug) ++ trollFilter)

  def stickyByCateg(categ: Categ): Fu[List[Topic]] =
    coll.list[Topic](byCategQuery(categ) ++ stickyQuery)

  def nextSlug(categ: Categ, name: String, it: Int = 1): Fu[String] = {
    val slug = Topic.nameToId(name) + ~(it != 1).option("-" + it)
    // also take troll topic into accounts
    TopicRepoTroll.byTree(categ.slug, slug) flatMap {
      _.isDefined.fold(
        nextSlug(categ, name, it + 1),
        fuccess(slug)
      )
    }
  }

  def incViews(topic: Topic) =
    coll.incFieldUnchecked($id(topic.id), "views")

  def byCategQuery(categ: Categ) = $doc("categId" -> categ.slug) ++ trollFilter
  def byCategNotStickyQuery(categ: Categ) = byCategQuery(categ) ++ notStickyQuery
}
{'fraction_non_alphanumeric': 0.14783324190894132, 'fraction_numerical': 0.0016456390565002743, 'mean_word_length': 4.255043227665706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2477689', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1303, 'n_words': 289}