<commit_before>import { copy } from "smc-util/misc2";
import { create } from "./types";

/*
This is a virtual table to make it simple from clients to
query about all usage ever of a specific file or directory
tree by a given user.

The usage times are the union of times both when patches
and times when the file was accessed.  Thus this would be
useful to see if a user opened a PDF file, say, even though
they didn't edit it.
*/

const LIMIT = 1000;

export const file_use_times = create({
  fields: {
    project_id: {
      type: "uuid",
      desc: "id of a project"
    },
    account_id: {
      type: "uuid",
      desc: "id of a user"
    },
    path: {
      type: "string",
      desc: "path to a specific file in the project"
    },
    edit_times: {
      type: "array",
      desc: `array of times (as ms since epoch) when the file was edited by the given account_id, sorted from newest to oldest. At most ${LIMIT} values are returned.`
    },
    access_times: {
      type: "array",
      desc: `array of times (as ms since epoch) when the file was accessed by the given account_id, sorted from newest to oldest.   At most ${LIMIT} values are returned.`
    }
  },
  rules: {
    virtual: true, // don't make an actual table
    desc: "File usage information.",
    anonymous: false,
    primary_key: ["project_id", "path"],
    user_query: {
      get: {
        options: [{ limit: LIMIT }],
        fields: {
          project_id: null,
          account_id: null,
          path: null,
          access_times: null,
          edit_times: null
        },
        // Actual query is implemented using this code below rather than an actual query directly.
        async instead_of_query(database, opts, cb): Promise<void> {
          const obj: any = copy(opts.query);
          const { project_id, account_id, path } = obj;
          if (project_id == null || account_id == null || path == null) {<commit_msg>small fix so projects start<commit_after>import { create } from "./types";

/*
This is a virtual table to make it simple from clients to
query about all usage ever of a specific file or directory
tree by a given user.

The usage times are the union of times both when patches
and times when the file was accessed.  Thus this would be
useful to see if a user opened a PDF file, say, even though
they didn't edit it.
*/

const LIMIT = 1000;

export const file_use_times = create({
  fields: {
    project_id: {
      type: "uuid",
      desc: "id of a project"
    },
    account_id: {
      type: "uuid",
      desc: "id of a user"
    },
    path: {
      type: "string",
      desc: "path to a specific file in the project"
    },
    edit_times: {
      type: "array",
      desc: `array of times (as ms since epoch) when the file was edited by the given account_id, sorted from newest to oldest. At most ${LIMIT} values are returned.`
    },
    access_times: {
      type: "array",
      desc: `array of times (as ms since epoch) when the file was accessed by the given account_id, sorted from newest to oldest.   At most ${LIMIT} values are returned.`
    }
  },
  rules: {
    virtual: true, // don't make an actual table
    desc: "File usage information.",
    anonymous: false,
    primary_key: ["project_id", "path"],
    user_query: {
      get: {
        options: [{ limit: LIMIT }],
        fields: {
          project_id: null,
          account_id: null,
          path: null,
          access_times: null,
          edit_times: null
        },
        // Actual query is implemented using this code below rather than an actual query directly.
        async instead_of_query(database, opts, cb): Promise<void> {
          const obj: any = Object.assign({}, opts.query);
          const { project_id, account_id, path } = obj;
          if (project_id == null || account_id == null || path == null) {
{'fraction_non_alphanumeric': 0.09765625, 'fraction_numerical': 0.00234375, 'mean_word_length': 2.438675022381379, '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': '119126', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1106, 'n_words': 483}