<commit_before>package lila.relation

import akka.actor._
import akka.pattern.pipe
import com.typesafe.config.Config

import lila.common.PimpedConfig._

final class Env(
    config: Config,
    db: lila.db.Env,
    hub: lila.hub.Env,
    getOnlineUserIds: () ⇒ Set[String],
    getUsername: String ⇒ Fu[String],
    system: ActorSystem,
    scheduler: lila.common.Scheduler) {

  private val settings = new {
    val CollectionRelation = config getString "collection.relation"
    val ActorNotifyFreq = config duration "actor.notify_freq"
    val ActorResyncFreq = config duration "actor.resync_freq"
    val ActorName = config getString "actor.name"
  }
  import settings._

  lazy val api = new RelationApi(
    cached = cached,
    actor = hub.actor.relation,
    getOnlineUserIds = getOnlineUserIds,
    timeline = hub.actor.timeline)

  private lazy val cached = new Cached

  lazy val autofollow = new Autofollow(api)

  private[relation] val actor = system.actorOf(Props(new RelationActor(
    socketHub = hub.socket.hub,
    getOnlineUserIds = getOnlineUserIds,
    getUsername = getUsername,
    api = api
  )), name = ActorName)

  {
    import scala.concurrent.duration._
    import makeTimeout.short
    import lila.hub.actorApi.WithUserIds

    scheduler.message(ActorNotifyFreq) {
      actor -> actorApi.NotifyMovement
    }

    scheduler.message(ActorResyncFreq) {
      actor -> actorApi.ReloadAllOnlineFriends
    }
  }

  private[relation] lazy val relationColl = db(CollectionRelation)
}

object Env {

  private def app = play.api.Play.current

  lazy val current = "[boot] relation" describes new Env(
    config = lila.common.PlayApp loadConfig "relation",
    db = lila.db.Env.current,
    hub = lila.hub.Env.current,
    getOnlineUserIds = () ⇒ lila.user.Env.current.onlineUserIdMemo.keySet,
    getUsername = lila.user.Env.current.usernameOrAnonymous,
    system = lila.common.PlayApp.system,
    scheduler = lila.common.PlayApp.scheduler)
}
<commit_msg>delay relation module scheduled tasks<commit_after>package lila.relation

import akka.actor._
import akka.pattern.pipe
import com.typesafe.config.Config

import lila.common.PimpedConfig._

final class Env(
    config: Config,
    db: lila.db.Env,
    hub: lila.hub.Env,
    getOnlineUserIds: () ⇒ Set[String],
    getUsername: String ⇒ Fu[String],
    system: ActorSystem,
    scheduler: lila.common.Scheduler) {

  private val settings = new {
    val CollectionRelation = config getString "collection.relation"
    val ActorNotifyFreq = config duration "actor.notify_freq"
    val ActorResyncFreq = config duration "actor.resync_freq"
    val ActorName = config getString "actor.name"
  }
  import settings._

  lazy val api = new RelationApi(
    cached = cached,
    actor = hub.actor.relation,
    getOnlineUserIds = getOnlineUserIds,
    timeline = hub.actor.timeline)

  private lazy val cached = new Cached

  lazy val autofollow = new Autofollow(api)

  private[relation] val actor = system.actorOf(Props(new RelationActor(
    socketHub = hub.socket.hub,
    getOnlineUserIds = getOnlineUserIds,
    getUsername = getUsername,
    api = api
  )), name = ActorName)

  {
    import scala.concurrent.duration._
    import makeTimeout.short
    import lila.hub.actorApi.WithUserIds

    scheduler.once(5 seconds) {
      scheduler.message(ActorNotifyFreq) {
        actor -> actorApi.NotifyMovement
      }

      scheduler.message(ActorResyncFreq) {
        actor -> actorApi.ReloadAllOnlineFriends
      }
    }
  }

  private[relation] lazy val relationColl = db(CollectionRelation)
}

object Env {

  private def app = play.api.Play.current

  lazy val current = "[boot] relation" describes new Env(
    config = lila.common.PlayApp loadConfig "relation",
    db = lila.db.Env.current,
    hub = lila.hub.Env.current,
    getOnlineUserIds = () ⇒ lila.user.Env.current.onlineUserIdMemo.keySet,
    getUsername = lila.user.Env.current.usernameOrAnonymous,
    system = lila.common.PlayApp.system,
    scheduler = lila.common.PlayApp.scheduler)
}

{'fraction_non_alphanumeric': 0.094400396432111, 'fraction_numerical': 0.0002477700693756194, 'mean_word_length': 3.4265350877192984, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1347864', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1272, 'n_words': 292}