<commit_before>package im.actor.server.api.rpc.service.messaging

import scala.concurrent._
import scala.concurrent.duration._

import akka.util.Timeout
import org.joda.time.DateTime
import slick.driver.PostgresDriver.api._

import im.actor.api.rpc._
import im.actor.api.rpc.messaging._
import im.actor.api.rpc.misc._
import im.actor.api.rpc.peers._

private[messaging] trait MessagingHandlers {
  self: MessagingServiceImpl ⇒

  import PeerHelpers._
  import im.actor.api.rpc.Implicits._

  override implicit val ec = actorSystem.dispatcher

  implicit val timeout = Timeout(5.seconds) // TODO: configurable

  override def jhandleSendMessage(outPeer: OutPeer, randomId: Long, message: Message, clientData: ClientData): Future[HandlerResult[ResponseSeqDate]] = {
    val authorizedAction = requireAuth(clientData).map { implicit client ⇒
      withOutPeer(client.userId, outPeer) {
        val dateTime = new DateTime
        val dateMillis = dateTime.getMillis

        val seqstateAction = outPeer.`type` match {
          case PeerType.Private ⇒
            DBIO.from(PrivatePeerManager.sendMessage(outPeer.id, client.userId, client.authId, randomId, dateTime, message))
          case PeerType.Group ⇒
            DBIO.from(GroupPeerManager.sendMessage(outPeer.id, client.userId, client.authId, randomId, dateTime, message))
        }

        for (seqstate ← seqstateAction) yield {
          val fromPeer = Peer(PeerType.Private, client.userId)
          val toPeer = outPeer.asPeer
          onMessage(Events.PeerMessage(fromPeer.asModel, toPeer.asModel, randomId, dateMillis, message))
          Ok(ResponseSeqDate(seqstate._1, seqstate._2, dateMillis))
        }
      }
    }

    db.run(toDBIOAction(authorizedAction map (_.transactionally)))
  }
}<commit_msg>perf(messaging): no transaction in SendMessage handler<commit_after>package im.actor.server.api.rpc.service.messaging

import scala.concurrent._
import scala.concurrent.duration._

import akka.util.Timeout
import org.joda.time.DateTime
import slick.driver.PostgresDriver.api._

import im.actor.api.rpc._
import im.actor.api.rpc.messaging._
import im.actor.api.rpc.misc._
import im.actor.api.rpc.peers._

private[messaging] trait MessagingHandlers {
  self: MessagingServiceImpl ⇒

  import PeerHelpers._
  import im.actor.api.rpc.Implicits._

  override implicit val ec = actorSystem.dispatcher

  implicit val timeout = Timeout(5.seconds) // TODO: configurable

  override def jhandleSendMessage(outPeer: OutPeer, randomId: Long, message: Message, clientData: ClientData): Future[HandlerResult[ResponseSeqDate]] = {
    val authorizedAction = requireAuth(clientData).map { implicit client ⇒
      withOutPeer(client.userId, outPeer) {
        val dateTime = new DateTime
        val dateMillis = dateTime.getMillis

        val seqstateAction = outPeer.`type` match {
          case PeerType.Private ⇒
            DBIO.from(PrivatePeerManager.sendMessage(outPeer.id, client.userId, client.authId, randomId, dateTime, message))
          case PeerType.Group ⇒
            DBIO.from(GroupPeerManager.sendMessage(outPeer.id, client.userId, client.authId, randomId, dateTime, message))
        }

        for (seqstate ← seqstateAction) yield {
          val fromPeer = Peer(PeerType.Private, client.userId)
          val toPeer = outPeer.asPeer
          onMessage(Events.PeerMessage(fromPeer.asModel, toPeer.asModel, randomId, dateMillis, message))
          Ok(ResponseSeqDate(seqstate._1, seqstate._2, dateMillis))
        }
      }
    }

    db.run(toDBIOAction(authorizedAction))
  }
}
{'fraction_non_alphanumeric': 0.09772535804549284, 'fraction_numerical': 0.0016849199663016006, 'mean_word_length': 3.560819462227913, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7325865', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1072, 'n_words': 227}