Commit 6fa1595f authored by nanahira's avatar nanahira

simplify

parent 102dd835
Pipeline #15312 canceled with stages
in 5 minutes and 1 second
......@@ -389,35 +389,32 @@ export class AppService extends ConsoleLogger {
}
const url = this.packageS3.getCdnUrl(archive.archiveFullPath);
try {
this.log(`Migrating hash: ${url} `);
this.log(`Downloading hash: ${url} `);
const hash = await this.checkHashFromUrl(url);
this.log(`Migrated hash: ${url} => ${hash}`);
return hash;
} catch (e) {
this.error(`Failed to migrate hash: ${url} => ${e.message}`);
this.error(`Failed to migrate hash: ${archive.path} => ${e.message}`);
return null;
}
}
async migrateHashes() {
const repo = this.db.getRepository(Archive);
const archivesToDo = await this.db.getRepository(Archive).find({ where: { hash: IsNull() }, select: ['path'] });
const hashMapToUpdate = new Map<string, string>();
const donePath = new Set<string>();
for (const archive of archivesToDo) {
if (hashMapToUpdate.has(archive.path)) {
const { path } = archive;
if (donePath.has(path)) {
continue;
}
this.log(`Migrating hash: ${path}`);
const hash = await this.getHashForMigrate(archive);
if (hash) {
hashMapToUpdate.set(archive.path, hash);
await repo.update({ path }, { hash });
this.log(`Migrated hash: ${path}`);
}
donePath.add(path);
}
await this.db.transaction(async (edb) => {
const repo = edb.getRepository(Archive);
const chunks = _.chunk(Array.from(hashMapToUpdate.entries()), 10000);
for (const chunk of chunks) {
await Promise.all(chunk.map(([path, hash]) => repo.update({ path }, { hash })));
}
});
return new BlankReturnMessageDto(200, 'success');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment