<commit_before>import config from "../config"
import execute from "./execute"

// Cache of table names for a database name
var _tableNames = {}

export default function truncate(tables) {
  let callback = function(tables) {
    if (!tables || tables.length === 0) {
      return null
    }

    var tableNames = tables
      .map(function(name) {
        return '"' + name + '"'
      })
      .join(", ")

    return execute("TRUNCATE " + tableNames + " RESTART IDENTITY CASCADE")
  }

  if (process.domain != null) {
    callback = process.domain.bind(callback)
  }

  if (!tables) {
    // No explicit list of tables was given
    // Do we have something cached?
    tables = _tableNames[config.get("name")]
    if (tables !== undefined) {
      return callback(tables)
    }

    // No cache query for all tables
    return execute(
        "SELECT table_schema, table_name, table_type " +
        "FROM information_schema.tables"
    ).then(function(result) {
        tables = []
        for (var i = 0; i < result.length; i += 1) {
          var row = result[i]

          if (row.table_type === "view") {
            continue
          }

          if ([
                "information_schema",
                "pg_catalog",
                "sql_features",
              ].indexOf(row.table_schema) >= 0) {
            continue
          }

          tables.push(row.table_name)
        }

        // Push this into the cache
        _tableNames[config.get("name")] = tables

        // Continue
        return callback(tables)
      }
    )
  }

  return callback(tables)
}
<commit_msg>:bug: Recognize and don't truncate views<commit_after>import config from "../config"
import execute from "./execute"

// Cache of table names for a database name
var _tableNames = {}

export default function truncate(tables) {
  let callback = function(tables) {
    if (!tables || tables.length === 0) {
      return null
    }

    var tableNames = tables
      .map(function(name) {
        return '"' + name + '"'
      })
      .join(", ")

    return execute("TRUNCATE " + tableNames + " RESTART IDENTITY CASCADE")
  }

  if (process.domain != null) {
    callback = process.domain.bind(callback)
  }

  if (!tables) {
    // No explicit list of tables was given
    // Do we have something cached?
    tables = _tableNames[config.get("name")]
    if (tables !== undefined) {
      return callback(tables)
    }

    // No cache query for all tables
    return execute(
        "SELECT table_schema, table_name, table_type " +
        "FROM information_schema.tables"
    ).then(function(result) {
        tables = []
        for (var i = 0; i < result.length; i += 1) {
          var row = result[i]

          if (row.table_type.toLowerCase() === "view") {
            continue
          }

          if ([
                "information_schema",
                "pg_catalog",
                "sql_features",
              ].indexOf(row.table_schema) >= 0) {
            continue
          }

          tables.push(row.table_name)
        }

        // Push this into the cache
        _tableNames[config.get("name")] = tables

        // Continue
        return callback(tables)
      }
    )
  }

  return callback(tables)
}

{'fraction_non_alphanumeric': 0.12155038759689922, 'fraction_numerical': 0.00248062015503876, 'mean_word_length': 1.8675555555555556, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1956214', 'n_tokens_mistral': 951, 'n_tokens_neox': 907, 'n_words': 247}