Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/util/db-schema/listings.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Table of directory listings.7*/89import { Table } from "./types";1011export const WATCH_TIMEOUT_MS = 60000;1213// Maximum number of paths to keep in listings tables for this project.14// NOTE: for now we're just using a limit query to only load this many15// when initializing things. We might have more in the database until16// synctable.delete gets fully and properly initialized. The main goal17// is to not waste bandwidth and memory in browsers.18export const MAX_PATHS = 50;1920// Maximum number of entries in a directory listing. If this is exceeded21// we sort by last modification time, take only the first MAX_FILES_PER_PATH22// most recent entries, and set missing to the number that are missing.23// This was 100 for a long time -- I'm upping it to 200 since at a 10024// it has worked very well without any excessive load issues.25export const MAX_FILES_PER_PATH = 200;2627import type { DirectoryListingEntry } from "@cocalc/util/types";2829export interface Listing {30path: string;31project_id?: string;32compute_server_id?: number;33listing?: DirectoryListingEntry[];34time?: Date;35interest?: Date;36missing?: number;37error?: string;38deleted?: string[];39}4041Table({42name: "listings",43fields: {44project_id: {45type: "uuid",46desc: "The project id.",47},48compute_server_id: {49type: "integer",50desc: "The compute server id. 0 or not given means 'the main project'.",51},52path: {53type: "string",54desc: "The directory that this is a listing of. Should not start or end with a slash and is relative to home directory of project.",55},56time: {57type: "timestamp",58desc: "When this directory listing was obtained.",59},60interest: {61type: "timestamp",62desc: "When a browser last said 'I care about contents of this directory'.",63},64listing: {65type: "array",66pg_type: "JSONB[]",67desc: "The directory listing itself.",68},69missing: {70type: "number",71desc: "If the listing is truncated due to being too large this is the number of missing entries. The oldest entries are missing.",72},73error: {74type: "string",75desc: "Set if there is an error computing the directory listing, e.g., if there is no directory this may happen. This will be cleared once the listing is successfully computed.",76},77deleted: {78type: "array",79pg_type: "TEXT[]",80desc: "Paths within this directory that have been explicitly deleted by a user",81},82},83rules: {84desc: "Directory listings in projects",85primary_key: ["project_id", "path", "compute_server_id"],86// this is necessary only for schema migration from befor we had compute_server_id as a column.87default_primary_key_value: { compute_server_id: 0 },88user_query: {89get: {90pg_where: ["projects"],91options: [{ order_by: "-interest" }, { limit: MAX_PATHS }],92fields: {93project_id: null,94compute_server_id: null,95path: null,96time: null,97listing: null,98missing: null,99interest: null,100error: null,101deleted: null,102},103},104set: {105// same privs as project, since compute servers are treated as a user. Plus listings isn't a106// security risk.107delete: true,108fields: {109project_id: "project_id",110compute_server_id: true,111path: true,112listing: true,113missing: true,114time: true,115interest: true,116error: true,117deleted: true,118},119},120},121122project_query: {123get: {124pg_where: [{ "project_id = $::UUID": "project_id" }],125options: [{ order_by: "-interest" }, { limit: 3 }],126fields: {127project_id: null,128compute_server_id: null,129path: null,130time: null,131listing: null,132missing: null,133interest: null,134error: null,135deleted: null,136},137},138set: {139// delete=true, since project *IS* allowed to delete entries140// in this table (used for purging tracked listings).141delete: true,142fields: {143project_id: "project_id",144compute_server_id: true,145path: true,146listing: true,147missing: true,148time: true,149interest: true,150error: true,151deleted: true,152},153},154},155},156});157158159