<commit_before>package controllers

import javax.inject.Inject

import controllers.Requests.AuthRequest
import controllers.routes.{Application => self}
import db.ProjectTable
import db.dao.ModelFilter
import db.driver.OrePostgresDriver.api._
import db.model.Models
import db.query.ModelQueries.{await, unwrapFilter}
import models.project.Project._
import models.project.{Flag, Project, Version}
import models.user.User
import ore.permission._
import ore.permission.scope.GlobalScope
import ore.project.Categories.Category
import ore.project.{Categories, ProjectSortingStrategies}
import play.api.i18n.MessagesApi
import play.api.libs.ws.WSClient
import play.api.mvc._
import util.Conf._
import util.DataUtils
import views.{html => views}

/**
  * Main entry point for application.
  */
class Application @Inject()(override val messagesApi: MessagesApi, implicit val ws: WSClient) extends BaseController {

  private def FlagAction = Authenticated andThen PermissionAction[AuthRequest](ReviewFlags)

  /**
    * Display the home page.
    *
    * @return Home page
    */
  def showHome(categories: Option[String], query: Option[String], sort: Option[Int]) = Action { implicit request =>
    // Get categories and sort strategy
    var categoryArray: Array[Category] = categories.map(Categories.fromString).orNull
    val s = sort.map(ProjectSortingStrategies.withId(_).get).getOrElse(ProjectSortingStrategies.Default)

    new Object().asInstanceOf[Int]

    // Determine filter
    val canHideProjects = User.current.isDefined && (User.current.get can HideProjects in GlobalScope)
    var filter: ProjectTable => Rep[Boolean] = query.map { q =>
      // Search filter + visible
      var f  = Models.Projects.searchFilter(q)
      if (!canHideProjects) f = f && (_.isVisible)
      f
    }.orNull[ModelFilter[ProjectTable, Project]]
    if (filter == null && !canHideProjects) filter = _.isVisible

    val projects = await(Models.Projects.collect(filter, categoryArray, InitialLoad, -1, s)).get
    if (categoryArray != null && Categories.visible.toSet.equals(categoryArray.toSet)) categoryArray = null
    Ok(views.home(projects, Option(categoryArray), s))
  }

  /**<commit_msg>Remove test error<commit_after>package controllers

import javax.inject.Inject

import controllers.Requests.AuthRequest
import controllers.routes.{Application => self}
import db.ProjectTable
import db.dao.ModelFilter
import db.driver.OrePostgresDriver.api._
import db.model.Models
import db.query.ModelQueries.{await, unwrapFilter}
import models.project.Project._
import models.project.{Flag, Project, Version}
import models.user.User
import ore.permission._
import ore.permission.scope.GlobalScope
import ore.project.Categories.Category
import ore.project.{Categories, ProjectSortingStrategies}
import play.api.i18n.MessagesApi
import play.api.libs.ws.WSClient
import play.api.mvc._
import util.Conf._
import util.DataUtils
import views.{html => views}

/**
  * Main entry point for application.
  */
class Application @Inject()(override val messagesApi: MessagesApi, implicit val ws: WSClient) extends BaseController {

  private def FlagAction = Authenticated andThen PermissionAction[AuthRequest](ReviewFlags)

  /**
    * Display the home page.
    *
    * @return Home page
    */
  def showHome(categories: Option[String], query: Option[String], sort: Option[Int]) = Action { implicit request =>
    // Get categories and sort strategy
    var categoryArray: Array[Category] = categories.map(Categories.fromString).orNull
    val s = sort.map(ProjectSortingStrategies.withId(_).get).getOrElse(ProjectSortingStrategies.Default)
    
    // Determine filter
    val canHideProjects = User.current.isDefined && (User.current.get can HideProjects in GlobalScope)
    var filter: ProjectTable => Rep[Boolean] = query.map { q =>
      // Search filter + visible
      var f  = Models.Projects.searchFilter(q)
      if (!canHideProjects) f = f && (_.isVisible)
      f
    }.orNull[ModelFilter[ProjectTable, Project]]
    if (filter == null && !canHideProjects) filter = _.isVisible

    val projects = await(Models.Projects.collect(filter, categoryArray, InitialLoad, -1, s)).get
    if (categoryArray != null && Categories.visible.toSet.equals(categoryArray.toSet)) categoryArray = null
    Ok(views.home(projects, Option(categoryArray), s))
  }

  /**
{'fraction_non_alphanumeric': 0.10908671586715867, 'fraction_numerical': 0.0013837638376383763, 'mean_word_length': 4.4829329962073325, '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': '2865867', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1239, 'n_words': 312}