<commit_before>package com.innoq.rocaplay
package infra.issues

import domain.Page
import domain.issues.IssueRepository

import scala.concurrent.{ExecutionContext, Future}
import play.api.db.DB
import anorm._
import anorm.SqlParser._
import com.innoq.rocaplay.domain.issues.Issue
import org.joda.time.DateTime
import play.api.Application

class AnormIssueRepository(
    application: Application,
    executionContext: ExecutionContext) extends IssueRepository {

  private implicit val app = application
  private implicit val ec = executionContext

  override def save(issue: Issue) = Future {
    val result = DB.withConnection {
      implicit connection =>
        SQL"""
            insert into issue(id, project_name, priority, issue_type, summary, exception_stack_trace, description,
            reporter, component_name, component_version, processing_state, open_date, close_date, close_action,
            assignee, comment) values(${issue.id}, ${issue.projectName}, ${issue.priority}, ${issue.issueType},
            ${issue.summary}, ${issue.exceptionStackTrace}, ${issue.description},
            ${issue.reporter}, ${issue.componentName}, ${issue.componentVersion}, ${issue.processingState},
            ${issue.openDate.getMillis}, ${issue.closeDate.map(_.getMillis)}, ${issue.closeAction}, ${issue.assignee}, ${issue.comment})
             """.executeUpdate()
    }
  }

  override def findByProjectName(projectName: String, offset: Int, count: Int) = Future {
    val issues = DB.withConnection {
      implicit c =>
        SQL("select * from issue where project_name like {projectName} limit {count} offset {offset}")
          .on(
            'projectName -> s"%$projectName%",
            'count -> count,
            'offset -> offset
          )
          .as(issueParser.*)
    }
    val total = DB.withConnection {
      implicit c =>
        SQL("select count(*) from issue where project_name like {projectName}")
          .on('projectName -> s"%$projectName%")
          .as(scalar[Long].single)
    }
    Page(issues, offset, total)
  }<commit_msg>Execute query for issues and for total with the same connection<commit_after>package com.innoq.rocaplay
package infra.issues

import domain.Page
import domain.issues.IssueRepository

import scala.concurrent.{ExecutionContext, Future}
import play.api.db.DB
import anorm._
import anorm.SqlParser._
import com.innoq.rocaplay.domain.issues.Issue
import org.joda.time.DateTime
import play.api.Application

class AnormIssueRepository(
    application: Application,
    executionContext: ExecutionContext) extends IssueRepository {

  private implicit val app = application
  private implicit val ec = executionContext

  override def save(issue: Issue) = Future {
    val result = DB.withConnection {
      implicit connection =>
        SQL"""
            insert into issue(id, project_name, priority, issue_type, summary, exception_stack_trace, description,
            reporter, component_name, component_version, processing_state, open_date, close_date, close_action,
            assignee, comment) values(${issue.id}, ${issue.projectName}, ${issue.priority}, ${issue.issueType},
            ${issue.summary}, ${issue.exceptionStackTrace}, ${issue.description},
            ${issue.reporter}, ${issue.componentName}, ${issue.componentVersion}, ${issue.processingState},
            ${issue.openDate.getMillis}, ${issue.closeDate.map(_.getMillis)}, ${issue.closeAction}, ${issue.assignee}, ${issue.comment})
             """.executeUpdate()
    }
  }

  override def findByProjectName(projectName: String, offset: Int, count: Int) = Future {
     DB.withConnection {
      implicit c =>
        val issues = SQL("select * from issue where project_name like {projectName} limit {count} offset {offset}")
          .on(
            'projectName -> s"%$projectName%",
            'count -> count,
            'offset -> offset
          )
          .as(issueParser.*)
        val total = SQL("select count(*) from issue where project_name like {projectName}")
          .on('projectName -> s"%$projectName%")
          .as(scalar[Long].single)
        Page(issues, offset, total)
     }
  }
{'fraction_non_alphanumeric': 0.11845266698702547, 'fraction_numerical': 0.0, 'mean_word_length': 3.2741273100616017, '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': '5939273', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1121, 'n_words': 285}