Commit 8912eb3e authored by nanahira's avatar nanahira

better record update

parent 1e72fbf4
Pipeline #15310 canceled with stages
in 1 minute and 55 seconds
......@@ -401,28 +401,24 @@ export class AppService extends ConsoleLogger {
async migrateHashes() {
const archivesToDo = await this.db.getRepository(Archive).find({ where: { hash: IsNull() }, select: ['id', 'hash', 'path'] });
const tmpMap = new Map<string, string>();
const archivesToSave: Archive[] = [];
const hashMapToUpdate = new Map<string, string>();
for (const archive of archivesToDo) {
if (tmpMap.has(archive.path)) {
archive.hash = tmpMap.get(archive.path);
} else {
const hash = await this.getHashForMigrate(archive);
if (hash) {
archive.hash = await this.getHashForMigrate(archive);
tmpMap.set(archive.path, archive.hash);
archivesToSave.push(archive);
}
if (hashMapToUpdate.has(archive.path)) {
continue;
}
const hash = await this.getHashForMigrate(archive);
if (hash) {
archive.hash = await this.getHashForMigrate(archive);
hashMapToUpdate.set(archive.path, archive.hash);
}
}
await this.db.transaction(async (edb) => {
const repo = edb.getRepository(Archive);
const chunks = _.chunk(archivesToSave, 10000);
const chunks = _.chunk(Array.from(hashMapToUpdate.entries()), 10000);
for (const chunk of chunks) {
await repo.save(chunk);
await Promise.all(chunk.map(([path, hash]) => repo.update({ path }, { hash })));
}
});
await this.db.getRepository(Archive).save(archivesToSave);
return new BlankReturnMessageDto(200, 'success');
}
......
......@@ -57,9 +57,7 @@ export class MirrorService extends ConsoleLogger {
for (const url of middlewares) {
try {
this.log(`Loading middleware ${url}`);
const { data } = await lastValueFrom(
this.http.get<ReturnMessage<MiddlewareInfo>>(url, { responseType: 'json' })
);
const { data } = await lastValueFrom(this.http.get<ReturnMessage<MiddlewareInfo>>(url, { responseType: 'json' }));
const middleware: Middleware = { url, info: data.data };
this.middlewares.push(middleware);
if (data.data.maxSize) {
......
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