<commit_before>async = require 'async'
requestFactory = require '../lib/request.js'
broadcastTasker = require '../lib/broadcast.js'
request = requestFactory()

messageCount    = 0
messageReceived = 0
messageInserted = 0
noMoreMessages  = false

taskCount     = 0
taskCompleted = 0

module.exports = 

    onBootstrap: (callback) ->

        if argv.faction
            bootstrap ->
                callback 'end'
        else
            callback()

dbQueue = async.queue (task, callback) ->

    task callback

, Config.Database.MaxParallel

bootstrap = (callback) ->

    indexes = [
        {time: -1}
        {'markup.SENDER1.plain': 1}
        {'markup.PLAYER1.plain': 1}
    ]

    # ensure indexes
    async.each indexes, (index, callback) ->

        Database.db.collection('Chat.Faction').ensureIndex index, callback

    , ->

        dbQueue.drain = ->
            callback() if noMoreMessages

        broadcast = broadcastTasker
            instanceId:         'req-broadcast-faction'
            type:               'faction'
            splitTimespanMS:    Config.Chat.SplitTimespanMS<commit_msg>added {time:1} index<commit_after>async = require 'async'
requestFactory = require '../lib/request.js'
broadcastTasker = require '../lib/broadcast.js'
request = requestFactory()

messageCount    = 0
messageReceived = 0
messageInserted = 0
noMoreMessages  = false

taskCount     = 0
taskCompleted = 0

module.exports = 

    onBootstrap: (callback) ->

        if argv.faction
            bootstrap ->
                callback 'end'
        else
            callback()

dbQueue = async.queue (task, callback) ->

    task callback

, Config.Database.MaxParallel

bootstrap = (callback) ->

    indexes = [
        {time: 1}
        {time: -1}
        {'markup.SENDER1.plain': 1}
        {'markup.PLAYER1.plain': 1}
    ]

    # ensure indexes
    async.each indexes, (index, callback) ->

        Database.db.collection('Chat.Faction').ensureIndex index, callback

    , ->

        dbQueue.drain = ->
            callback() if noMoreMessages

        broadcast = broadcastTasker
            instanceId:         'req-broadcast-faction'
            type:               'faction'
            splitTimespanMS:    Config.Chat.SplitTimespanMS
{'fraction_non_alphanumeric': 0.10858923008455719, 'fraction_numerical': 0.009790832220738763, 'mean_word_length': 2.0419485791610286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7640507', 'n_tokens_mistral': 675, 'n_tokens_neox': 635, 'n_words': 143}