mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-05 05:08:07 +02:00
fix: handle slow database update
This commit is contained in:
@@ -61,27 +61,45 @@ export default class GitHubDownload extends GitHubBase implements SourceBase {
|
|||||||
const originalPath = this.repository.originalCachePath;
|
const originalPath = this.repository.originalCachePath;
|
||||||
await storage.mk(originalPath);
|
await storage.mk(originalPath);
|
||||||
let progress = null;
|
let progress = null;
|
||||||
let progressInterval = setInterval(async () => {
|
let progressTimeout;
|
||||||
|
let inDownload = true;
|
||||||
|
|
||||||
|
const that = this;
|
||||||
|
async function updateProgress() {
|
||||||
if (progress) {
|
if (progress) {
|
||||||
await this.repository.updateStatus(
|
await that.repository.updateStatus(
|
||||||
this.repository.status,
|
that.repository.status,
|
||||||
progress.transferred
|
progress.transferred
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, 1000);
|
if (inDownload) {
|
||||||
|
progressTimeout = setTimeout(updateProgress, 1500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateProgress();
|
||||||
|
|
||||||
await storage.extractTar(
|
await storage.extractTar(
|
||||||
originalPath,
|
originalPath,
|
||||||
got
|
got
|
||||||
.stream(response.url)
|
.stream(response.url)
|
||||||
.on("downloadProgress", async (p) => {
|
.on("downloadProgress", async (p) => {
|
||||||
console.log(p);
|
inDownload = true;
|
||||||
progress = p;
|
progress = p;
|
||||||
})
|
})
|
||||||
.on("error", () => clearInterval(progressInterval))
|
.on("error", (error) => {
|
||||||
.on("end", () => clearInterval(progressInterval))
|
inDownload = false;
|
||||||
.on("close", () => clearInterval(progressInterval))
|
clearTimeout(progressTimeout);
|
||||||
|
})
|
||||||
|
.on("end", () => {
|
||||||
|
inDownload = false;
|
||||||
|
console.log("download finished");
|
||||||
|
clearTimeout(progressTimeout);
|
||||||
|
})
|
||||||
|
.on("close", () => clearTimeout(progressTimeout))
|
||||||
);
|
);
|
||||||
clearInterval(progressInterval);
|
|
||||||
|
inDownload = false;
|
||||||
|
clearTimeout(progressTimeout);
|
||||||
await this.repository.updateStatus("ready");
|
await this.repository.updateStatus("ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user