mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-12 18:32:44 +00:00
fix: attempt at avoiding double save
This commit is contained in:
@@ -74,7 +74,9 @@ export default class Repository {
|
||||
const token = await getToken(this);
|
||||
if (originalToken != token) {
|
||||
this._model.source.accessToken = token;
|
||||
await this._model.save();
|
||||
if (isConnected) {
|
||||
await this._model.save();
|
||||
}
|
||||
}
|
||||
this.checkedToken = true;
|
||||
return token;
|
||||
@@ -461,9 +463,11 @@ export default class Repository {
|
||||
span.setAttribute("repoId", this.repoId);
|
||||
try {
|
||||
await storage.rm(this.repoId);
|
||||
} finally {
|
||||
this.model.isReseted = true;
|
||||
await this.model.save();
|
||||
if (isConnected) {
|
||||
await this.model.save();
|
||||
}
|
||||
} finally {
|
||||
span.end();
|
||||
}
|
||||
}
|
||||
@@ -509,7 +513,9 @@ export default class Repository {
|
||||
|
||||
const files = await this.files();
|
||||
this._model.size = recursiveCount(files);
|
||||
await this._model.save();
|
||||
if (isConnected) {
|
||||
await this._model.save();
|
||||
}
|
||||
return this._model.size;
|
||||
} finally {
|
||||
span.end();
|
||||
|
||||
@@ -30,7 +30,11 @@ export default async function (job: SandboxedJob<Repository, void>) {
|
||||
) {
|
||||
return clearInterval(statusInterval);
|
||||
}
|
||||
if (repo.status && repo.model.statusMessage !== progress?.status) {
|
||||
if (
|
||||
progress &&
|
||||
repo.status &&
|
||||
repo.model.statusMessage !== progress?.status
|
||||
) {
|
||||
console.log(
|
||||
`[QUEUE] Progress: ${job.data.repoId} ${progress.status}`
|
||||
);
|
||||
@@ -45,12 +49,9 @@ export default async function (job: SandboxedJob<Repository, void>) {
|
||||
progress = o;
|
||||
job.updateProgress(o);
|
||||
}
|
||||
updateProgress({ status: "get_repo" });
|
||||
try {
|
||||
updateProgress({ status: "resetSate" });
|
||||
await repo.resetSate(RepositoryStatus.PREPARING, "");
|
||||
await repo.anonymize(updateProgress);
|
||||
updateProgress({ status: RepositoryStatus.READY });
|
||||
console.log(`[QUEUE] ${job.data.repoId} is downloaded`);
|
||||
} catch (error) {
|
||||
updateProgress({ status: "error" });
|
||||
@@ -65,7 +66,7 @@ export default async function (job: SandboxedJob<Repository, void>) {
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
job.updateProgress({ status: "error", error: error });
|
||||
clearInterval(statusInterval);
|
||||
await repo.updateStatus(RepositoryStatus.ERROR, error.message);
|
||||
span.recordException(error as Exception);
|
||||
console.log(`[QUEUE] ${job.data.repoId} is finished with an error`);
|
||||
|
||||
Reference in New Issue
Block a user