mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-06 05:38:09 +02:00
feat: remove cache of old repositories
This commit is contained in:
+9
-4
@@ -253,10 +253,15 @@ export default class Repository {
|
|||||||
this._model.size = { storage: 0, file: 0 };
|
this._model.size = { storage: 0, file: 0 };
|
||||||
this._model.originalFiles = null;
|
this._model.originalFiles = null;
|
||||||
// remove cache
|
// remove cache
|
||||||
return Promise.all([
|
return Promise.all([this._model.save(), this.removeCache()]);
|
||||||
this._model.save(),
|
}
|
||||||
storage.rm(this._model.repoId + "/"),
|
|
||||||
]);
|
/**
|
||||||
|
* Remove the cached files
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
async removeCache() {
|
||||||
|
return storage.rm(this._model.repoId + "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export function conferenceStatusCheck() {
|
|||||||
export function repositoryStatusCheck() {
|
export function repositoryStatusCheck() {
|
||||||
// check every 6 hours the status of the repositories
|
// check every 6 hours the status of the repositories
|
||||||
const job = schedule.scheduleJob("0 */6 * * *", async () => {
|
const job = schedule.scheduleJob("0 */6 * * *", async () => {
|
||||||
|
console.log("[schedule] Check repository status and unused repositories");
|
||||||
(
|
(
|
||||||
await AnonymizedRepositoryModel.find({ status: { $eq: "ready" } })
|
await AnonymizedRepositoryModel.find({ status: { $eq: "ready" } })
|
||||||
).forEach((data) => {
|
).forEach((data) => {
|
||||||
@@ -34,6 +35,16 @@ export function repositoryStatusCheck() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`Repository ${repo.repoId} is expired`);
|
console.log(`Repository ${repo.repoId} is expired`);
|
||||||
}
|
}
|
||||||
|
const sixMonthAgo = new Date();
|
||||||
|
sixMonthAgo.setMonth(sixMonthAgo.getMonth() - 6);
|
||||||
|
|
||||||
|
if (repo.model.lastView < sixMonthAgo) {
|
||||||
|
repo.removeCache().then(() => {
|
||||||
|
console.log(
|
||||||
|
`Repository ${repo.repoId} not visited for 6 months remove the cached files`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,6 +114,9 @@ export default class GitHubDownload extends GitHubBase implements SourceBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getFileContent(file: AnonymizedFile): Promise<Readable> {
|
async getFileContent(file: AnonymizedFile): Promise<Readable> {
|
||||||
|
if (await storage.exists(file.originalCachePath)) {
|
||||||
|
return storage.read(file.originalCachePath);
|
||||||
|
}
|
||||||
await this.download();
|
await this.download();
|
||||||
// update the file list
|
// update the file list
|
||||||
await this.repository.files({ force: true });
|
await this.repository.files({ force: true });
|
||||||
|
|||||||
Reference in New Issue
Block a user