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