<commit_before>package core

import akka.actor.Actor
import com.datastax.driver.core.{Cluster, Row, Session}
import domain.Tweet
import core.TweetReadActor.{CountAll, FindAll}

object TweetReadActor {
  case object FindAll
  case object CountAll
}

class TweetReadActor(cluster: Cluster) extends Actor with TweetReadOperations {
  val session = cluster.connect(Keyspaces.akkaCassandra)

  def receive: Receive = {
    case FindAll => sender ! findAllTweets
    case CountAll => sender ! countAllTweets
  }
}

private[core] trait TweetReadOperations extends CassandraCrud {
  import com.datastax.driver.core.querybuilder.{ QueryBuilder => QB }

  implicit def session: Session

  def buildTweet(r: Row): Tweet = {
    val id = r.getString("key")
    val user = r.getString("user_user")
    val text = r.getString("text")
    val createdAt = r.getDate("createdat")
    Tweet(id, user, text, createdAt)
  }

  def findAllTweets(): Either[ErrorMessage, List[Tweet]] = {
    val query = QB.select.all.from(ColumnFamilies.tweets)
    (gather(buildTweet) &= enumRS(session.execute(query))).runEither
  }

  def countAllTweets(): Long = {
    val query = QB.select.countAll().from(ColumnFamilies.tweets)
    session.execute(query).one.getLong(0)
  }

}<commit_msg>Prepared statements throughout<commit_after>package core

import akka.actor.Actor
import com.datastax.driver.core.{BoundStatement, Cluster, Row, Session}
import domain.Tweet
import core.TweetReadActor.{CountAll, FindAll}
import scala.collection.JavaConversions

object TweetReadActor {
  case object FindAll
  case object CountAll
}

class TweetReadActor(cluster: Cluster) extends Actor {
  val session = cluster.connect(Keyspaces.akkaCassandra)
  val selectAll = new BoundStatement(session.prepare("select * from tweets;"))
  val countAll  = new BoundStatement(session.prepare("select count(*) from tweets;"))
  import JavaConversions._

  def buildTweet(r: Row): Tweet = {
    val id = r.getString("key")
    val user = r.getString("user_user")
    val text = r.getString("text")
    val createdAt = r.getDate("createdat")
    Tweet(id, user, text, createdAt)
  }

  def receive: Receive = {
    case FindAll  =>
      sender ! Right(session.execute(selectAll).all().map(buildTweet).toList)
    case CountAll =>
      sender ! session.execute(countAll).one.getLong(0)
  }
}
{'fraction_non_alphanumeric': 0.11368511368511368, 'fraction_numerical': 0.000858000858000858, 'mean_word_length': 4.410672853828307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '3380851', 'n_tokens_mistral': 763, 'n_tokens_neox': 740, 'n_words': 171}