mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-10-19 14:17:20 +02:00
* perf: bound request work and resource usage * fix: address performance review regressions * fix: guard content expiration and dashboard state * fix: tolerate cache outages and retire derived paths * fix: revalidate expiration claims and status pagination * fix: retry interrupted repository metadata cleanup * fix: retire obsolete content cache storage * fix: activate tree metadata and recheck expiration claims * fix: fence cache publication across expiration * fix: recover staged trees and enforce cache lifecycle cleanup * fix: prune expired transforms during database outages * fix: finish conference removals and reload expiration candidates
36 lines
1.6 KiB
TypeScript
36 lines
1.6 KiB
TypeScript
import { Document, Model } from "mongoose";
|
|
import { RepositoryStatus } from "./types";
|
|
|
|
type ContentSnapshot = Document & {
|
|
status?: RepositoryStatus;
|
|
statusDate?: Date;
|
|
anonymizeDate?: Date;
|
|
options: { expirationMode?: string; expirationDate?: Date };
|
|
githubAccess?: { revision?: string };
|
|
};
|
|
|
|
// Embedded content and lifecycle state live in one document. Claim and clear
|
|
// them in one conditional write so an extension or rebuild cannot interleave.
|
|
export async function expireEmbeddedContent<T extends ContentSnapshot>(
|
|
model: Model<T>, data: T, fields: Record<string, unknown>, unset: Record<string, ""> = {}
|
|
) {
|
|
const now = new Date();
|
|
const result = await model.updateOne({
|
|
_id: data._id,
|
|
status: data.status ?? { $exists: false },
|
|
statusDate: data.statusDate ?? { $exists: false },
|
|
anonymizeDate: data.anonymizeDate ?? { $exists: false },
|
|
"options.expirationMode": data.options.expirationMode ?? { $exists: false },
|
|
"options.expirationDate": data.options.expirationDate ?? { $exists: false },
|
|
"githubAccess.revision": data.githubAccess?.revision ?? { $exists: false },
|
|
$and: [
|
|
{ status: { $in: [RepositoryStatus.READY, RepositoryStatus.EXPIRING] } },
|
|
{ "options.expirationMode": { $ne: "never" } },
|
|
{ "options.expirationDate": { $lte: now } },
|
|
],
|
|
}, { $set: { ...fields, status: RepositoryStatus.EXPIRED, statusDate: now }, $unset: unset }).exec();
|
|
if (!result.matchedCount) return;
|
|
data.set({ ...fields, status: RepositoryStatus.EXPIRED, statusDate: now });
|
|
for (const key of Object.keys(unset)) data.set(key, undefined);
|
|
}
|