rephrase input and filer for resvered folder

This commit is contained in:
Maidul Islam
2024-06-12 15:56:47 -04:00
parent 87df5a2749
commit 30f3dac35f
2 changed files with 23 additions and 6 deletions
@@ -327,6 +327,24 @@ export const snapshotDALFactory = (db: TDbClient) => {
} }
}; };
/**
* Prunes excess snapshots from the database to ensure only a specified number of recent snapshots are retained for each folder.
*
* This function operates in three main steps:
* 1. Pruning snapshots from root/non-versioned folders.
* 2. Pruning snapshots from versioned folders.
* 3. Removing orphaned snapshots that do not belong to any existing folder or folder version.
*
* The function processes snapshots in batches, determined by the `PRUNE_FOLDER_BATCH_SIZE` constant,
* to manage the large datasets without overwhelming the DB.
*
* Steps:
* - Fetch a batch of folder IDs.
* - For each batch, use a Common Table Expression (CTE) to rank snapshots within each folder by their creation date.
* - Identify and delete snapshots that exceed the project's point-in-time version limit (`pitVersionLimit`).
* - Repeat the process for versioned folders.
* - Finally, delete orphaned snapshots that do not have an associated folder.
*/
const pruneExcessSnapshots = async () => { const pruneExcessSnapshots = async () => {
const PRUNE_FOLDER_BATCH_SIZE = 10000; const PRUNE_FOLDER_BATCH_SIZE = 10000;
@@ -337,6 +355,7 @@ export const snapshotDALFactory = (db: TDbClient) => {
while (true) { while (true) {
const folderBatch = await db(TableName.SecretFolder) const folderBatch = await db(TableName.SecretFolder)
.where("id", ">", uuidOffset) .where("id", ">", uuidOffset)
.where("isReserved", false)
.orderBy("id", "asc") .orderBy("id", "asc")
.limit(PRUNE_FOLDER_BATCH_SIZE) .limit(PRUNE_FOLDER_BATCH_SIZE)
.select("id"); .select("id");
@@ -345,7 +364,7 @@ export const snapshotDALFactory = (db: TDbClient) => {
if (folderBatch.length) { if (folderBatch.length) {
try { try {
logger.info(`Pruning snapshots in range ${batchEntries[0]}:${batchEntries[batchEntries.length - 1]}`); logger.info(`Pruning snapshots in [range=${batchEntries[0]}:${batchEntries[batchEntries.length - 1]}]`);
await db(TableName.Snapshot) await db(TableName.Snapshot)
.with("snapshot_cte", (qb) => { .with("snapshot_cte", (qb) => {
void qb void qb
@@ -56,12 +56,10 @@ export const PointInTimeVersionLimitSection = () => {
return ( return (
<div className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4"> <div className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
<div className="flex w-full items-center justify-between"> <div className="flex w-full items-center justify-between">
<p className="text-xl font-semibold">Point in Time Recovery</p> <p className="text-xl font-semibold">Version Retention</p>
</div> </div>
<p className="mb-4 mt-2 max-w-2xl text-sm text-gray-400"> <p className="mb-4 mt-2 max-w-2xl text-sm text-gray-400">
This defines the maximum number of folder snapshots, secret versions, and folder versions This defines the maximum number of recent secret versions to keep per folder. Excess versions will be removed at midnight (UTC) each day.
that are retained by the system. The cleanup of excess snapshots and versions happens once a
day on midnight of UTC.
</p> </p>
<form onSubmit={handleSubmit(handleVersionLimitSubmit)} autoComplete="off"> <form onSubmit={handleSubmit(handleVersionLimitSubmit)} autoComplete="off">
<div className="max-w-xs"> <div className="max-w-xs">
@@ -73,7 +71,7 @@ export const PointInTimeVersionLimitSection = () => {
<FormControl <FormControl
isError={Boolean(error)} isError={Boolean(error)}
errorText={error?.message} errorText={error?.message}
label="Version Limit" label="Recent versions to keep"
> >
<Input {...field} type="number" min={1} step={1} isDisabled={!isAdmin} /> <Input {...field} type="number" min={1} step={1} isDisabled={!isAdmin} />
</FormControl> </FormControl>