<commit_before>const fs = require('fs')
const pify = require('pify')
const readFile = pify(fs.readFile)
const db = require('./db')
const options = require('./options')
const logger = require('./logger')

function pullToken (token) {
  const sql = `delete from pairing_tokens
    where token=$1
    returning name, created < now() - interval '1 hour' as expired`
  return db.one(sql, [token])
}

function unpair (deviceId) {
  // TODO new-admin: We should remove all configs related to that device. This can get tricky.
  return db.tx(async t => {
    await t.none('DELETE FROM devices WHERE device_id=$1', [deviceId])
    await t.none('DELETE FROM machine_pings WHERE device_id=$1', [deviceId])
    await t.none('DELETE FROM machine_network_heartbeat WHERE device_id=$1', [deviceId])
    await t.none('DELETE FROM machine_network_performance WHERE device_id=$1', [deviceId])
  })
}

function pair (token, deviceId, machineModel) {
  return pullToken(token)
    .then(r => {
      if (r.expired) return false

      const insertSql = `insert into devices (device_id, name) values ($1, $2)
    on conflict (device_id)
    do update set paired=TRUE, display=TRUE`<commit_msg>fix: use Promise.all instead await<commit_after>const fs = require('fs')
const pify = require('pify')
const readFile = pify(fs.readFile)
const db = require('./db')
const options = require('./options')
const logger = require('./logger')

function pullToken (token) {
  const sql = `delete from pairing_tokens
    where token=$1
    returning name, created < now() - interval '1 hour' as expired`
  return db.one(sql, [token])
}

function unpair (deviceId) {
  // TODO new-admin: We should remove all configs related to that device. This can get tricky.
  return db.tx(t => {
    const q1 = t.none('DELETE FROM devices WHERE device_id=$1', [deviceId])
    const q2 = t.none('DELETE FROM machine_pings WHERE device_id=$1', [deviceId])
    const q3 = t.none('DELETE FROM machine_network_heartbeat WHERE device_id=$1', [deviceId])
    const q4 = t.none('DELETE FROM machine_network_performance WHERE device_id=$1', [deviceId])
    return Promise.all([q1, q2, q3, q4])
  })
}

function pair (token, deviceId, machineModel) {
  return pullToken(token)
    .then(r => {
      if (r.expired) return false

      const insertSql = `insert into devices (device_id, name) values ($1, $2)
    on conflict (device_id)
    do update set paired=TRUE, display=TRUE`
{'fraction_non_alphanumeric': 0.128099173553719, 'fraction_numerical': 0.009917355371900827, 'mean_word_length': 4.140127388535032, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1014293', 'n_tokens_mistral': 756, 'n_tokens_neox': 749, 'n_words': 249}