fix persistance bugs

This commit is contained in:
tdurieux
2026-05-06 20:00:59 +03:00
parent 67cb2538b1
commit bd8656206a
11 changed files with 133 additions and 9 deletions
+6 -1
View File
@@ -178,7 +178,12 @@ export default class Gist {
await this.updateStatus(RepositoryStatus.READY);
await AnonymizedGistModel.updateOne(
{ _id: this._model._id },
{ $set: { anonymizeDate: this._model.anonymizeDate } }
{
$set: {
anonymizeDate: this._model.anonymizeDate,
gist: this._model.gist,
},
}
).exec();
}
}
+6 -1
View File
@@ -192,7 +192,12 @@ export default class PullRequest {
await this.updateStatus(RepositoryStatus.READY);
await AnonymizedPullRequestModel.updateOne(
{ _id: this._model._id },
{ $set: { anonymizeDate: this._model.anonymizeDate } }
{
$set: {
anonymizeDate: this._model.anonymizeDate,
pullRequest: this._model.pullRequest,
},
}
).exec();
}
}
+14 -3
View File
@@ -213,15 +213,14 @@ export default class Repository {
/**
* Check the status of the repository
*/
check() {
async check() {
if (
this._model.options.expirationMode !== "never" &&
this.status == RepositoryStatus.READY &&
this._model.options.expirationDate
) {
if (this._model.options.expirationDate <= new Date()) {
this._model.status = RepositoryStatus.EXPIRED;
this.expire();
await this.expire();
}
}
if (
@@ -384,6 +383,18 @@ export default class Repository {
commit: newCommit,
});
if (isConnected) {
await AnonymizedRepositoryModel.updateOne(
{ _id: this._model._id },
{
$set: {
"source.commit": newCommit,
"source.commitDate": this._model.source.commitDate,
anonymizeDate: this._model.anonymizeDate,
},
}
).exec();
}
await this.resetSate(RepositoryStatus.PREPARING);
await downloadQueue.add(this.repoId, { repoId: this.repoId }, {
jobId: this.repoId,
+11
View File
@@ -166,6 +166,16 @@ router.post(
updateGistModel(gist.model, gistUpdate);
gist.model.conference = gistUpdate.conference;
await AnonymizedGistModel.updateOne(
{ _id: gist.model._id },
{
$set: {
options: gist.model.options,
conference: gist.model.conference,
anonymizeDate: gist.model.anonymizeDate,
},
}
).exec();
await gist.updateStatus(RepositoryStatus.PREPARING);
await gist.updateIfNeeded({ force: true });
res.json(gist.toJSON());
@@ -200,6 +210,7 @@ router.post("/", async (req: express.Request, res: express.Response) => {
gist.model.conference = gistUpdate.conference;
await gist.model.save();
await gist.anonymize();
res.send(gist.toJSON());
} catch (error) {
+11
View File
@@ -186,6 +186,16 @@ router.post(
updatePullRequestModel(pullRequest.model, pullRequestUpdate);
// TODO handle conference
pullRequest.model.conference = pullRequestUpdate.conference;
await AnonymizedPullRequestModel.updateOne(
{ _id: pullRequest.model._id },
{
$set: {
options: pullRequest.model.options,
conference: pullRequest.model.conference,
anonymizeDate: pullRequest.model.anonymizeDate,
},
}
).exec();
await pullRequest.updateStatus(RepositoryStatus.PREPARING);
await pullRequest.updateIfNeeded({ force: true });
res.json(pullRequest.toJSON());
@@ -222,6 +232,7 @@ router.post("/", async (req: express.Request, res: express.Response) => {
pullRequest.conference = pullRequestUpdate.conference;
await pullRequest.model.save();
await pullRequest.anonymize();
res.send(pullRequest.toJSON());
} catch (error) {
+11
View File
@@ -480,6 +480,17 @@ router.post(
}
}
repo.model.conference = repoUpdate.conference;
await AnonymizedRepositoryModel.updateOne(
{ _id: repo.model._id },
{
$set: {
options: repo.model.options,
source: repo.model.source,
conference: repo.model.conference,
anonymizeDate: repo.model.anonymizeDate,
},
}
).exec();
await repo.updateStatus(RepositoryStatus.PREPARING);
res.json({ status: repo.status });
await downloadQueue.add(repo.repoId, { repoId: repo.repoId }, { jobId: repo.repoId });
+1 -1
View File
@@ -83,7 +83,7 @@ export async function getRepo(
return null;
}
repo.check();
await repo.check();
}
return repo;
} catch (error) {
+2 -2
View File
@@ -35,10 +35,10 @@ export function repositoryStatusCheck() {
status: { $eq: "ready" },
isReseted: { $eq: false },
})
).forEach((data) => {
).forEach(async (data) => {
const repo = new Repository(data);
try {
repo.check();
await repo.check();
} catch {
logger.info("repository expired", { repoId: repo.repoId });
}