<commit_before>{ get } = require (
  "../../../workers/social/lib/social/models/socialapi/requests.coffee"
)

{ dash } = require 'bongo'

module.exports = (req, res) ->
  koding     = require './bongo'
  {JMachine} = koding.models

  errMsg = (msg)->
    {
      "description" : msg
      "error"       : "bad_request"
    }

  {key} = req.query

  unless key
    return res.status(401).send errMsg "key is required"

  # Hardcoding is wrong, however this key won't change
  # depending on environments, so there's point of
  # putting it in config : SA
  unless key is "<KEY>"
    return res.status(401).send errMsg "key is wrong"

  url = "/payments/customers"

  get url, {}, (err, usernames)->
    return res.status(400).send err  if err

    response = []
    chunk    = []
    queue    = []

    while (usernames.length > 0)
      chunk = usernames.splice(0,10)
      chunk.forEach (username)->
        queue.push -> JMachine.fetchByUsername username, (err, machines)->
          if err
            queue.fin()
          else
            slugs = []
            machines.forEach (machine)->
              slugs.push  machine.data.slug  if machine.data.meta.alwaysOn

            resp = { "username" : username, "vms" : slugs }
            response.push resp

            queue.fin()

    dash queue, -> res.status(200).send response
<commit_msg>server: remove unnecessary partition to chunk<commit_after>{ get } = require (
  "../../../workers/social/lib/social/models/socialapi/requests.coffee"
)

{ dash } = require 'bongo'

module.exports = (req, res) ->
  koding     = require './bongo'
  {JMachine} = koding.models

  errMsg = (msg)->
    {
      "description" : msg
      "error"       : "bad_request"
    }

  {key} = req.query

  unless key
    return res.status(401).send errMsg "key is required"

  # Hardcoding is wrong, however this key won't change
  # depending on environments, so there's point of
  # putting it in config : SA
  unless key is "<KEY>"
    return res.status(401).send errMsg "key is wrong"

  url = "/payments/customers"

  get url, {}, (err, usernames)->
    return res.status(400).send err  if err

    response = []
    queue    = []

    usernames.forEach (username)->
      queue.push -> JMachine.fetchByUsername username, (err, machines)->
        if err
          queue.fin()
        else
          slugs = []
          machines.forEach (machine)->
            slugs.push  machine.data.slug  if machine.data.meta.alwaysOn

          response.push { "username" : username, "vms" : slugs }
          queue.fin()

    dash queue, -> res.status(200).send response

{'fraction_non_alphanumeric': 0.13292354975028814, 'fraction_numerical': 0.010756819054936612, 'mean_word_length': 2.1872705018359855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, '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': '3086607', 'n_tokens_mistral': 832, 'n_tokens_neox': 794, 'n_words': 217}