Commit a46f171d authored by nanahira's avatar nanahira

Merge branch 'master' into file-relation

parents 8c7335f8 183a4730
...@@ -40,7 +40,7 @@ const configModule = ConfigModule.forRoot(); ...@@ -40,7 +40,7 @@ const configModule = ConfigModule.forRoot();
username: config.get('DB_USER'), username: config.get('DB_USER'),
password: config.get('DB_PASS'), password: config.get('DB_PASS'),
database: config.get('DB_NAME'), database: config.get('DB_NAME'),
//logging: true, logging: !!config.get('DB_LOGGING'),
}; };
}, },
}), }),
......
...@@ -47,7 +47,7 @@ export class ArchiveTask { ...@@ -47,7 +47,7 @@ export class ArchiveTask {
const archive = new Archive(); const archive = new Archive();
archive.path = this.path; archive.path = this.path;
archive.role = this.role; archive.role = this.role;
archive.files = []; archive.files = this.exactFilePaths;
archive.containingFiles = this.exactFilePaths.map((filePath) => ArchiveFile.fromPath(filePath)); archive.containingFiles = this.exactFilePaths.map((filePath) => ArchiveFile.fromPath(filePath));
return archive; return archive;
} }
......
...@@ -138,34 +138,33 @@ export class UpdateService extends ConsoleLogger { ...@@ -138,34 +138,33 @@ export class UpdateService extends ConsoleLogger {
} }
async getPartPackageMetalink(id: string, depotDto: DepotDto, version: string, requestedFiles: string[]) { async getPartPackageMetalink(id: string, depotDto: DepotDto, version: string, requestedFiles: string[]) {
const build = await this.getBuild(id, depotDto, version, (qb) => qb.select('build.id'));
let clock = moment(); let clock = moment();
this.log('part 1'); this.log('part 1');
const tryExactArchives = await this.getArchives( const tryExactArchiveQuery = this.db
id, .getRepository(Archive)
depotDto, .createQueryBuilder('archive')
version, .where('archive.buildId = :buildId', { buildId: build.id })
(qb) => .andWhere('archive.role != :partRole', { partRole: ArchiveType.Part });
qb /*.addSelect(`array(${qb
.andWhere('archive.role != :partRole', { partRole: ArchiveType.Part })
/*.addSelect(`array(${qb
.subQuery() .subQuery()
.select('file.path') .select('file.path')
.from(ArchiveFile, 'file') .from(ArchiveFile, 'file')
.where('file.archiveId = archive.id') .where('file.archiveId = archive.id')
.getQuery()})`, 'allFiles')*/ .getQuery()})`, 'allFiles')*/
.andWhere( tryExactArchiveQuery
`:requestedFiles = array(${qb .andWhere(
.subQuery() `:requestedFiles = array(${tryExactArchiveQuery
.select('file.path') .subQuery()
.from(ArchiveFile, 'file') .select('file.path')
.where('file.archiveId = archive.id') .from(ArchiveFile, 'file')
.getQuery()})`, .where('file.archiveId = archive.id')
{ requestedFiles: requestedFiles } .getQuery()})`,
) { requestedFiles: requestedFiles }
// .orderBy('archive.size', 'ASC') )
.limit(1), // .orderBy('archive.size', 'ASC')
true .limit(1);
); const tryExactArchives = await tryExactArchiveQuery.getMany();
if (tryExactArchives.length) { if (tryExactArchives.length) {
return { return {
cdnUrl: this.cdnUrl, cdnUrl: this.cdnUrl,
...@@ -173,27 +172,51 @@ export class UpdateService extends ConsoleLogger { ...@@ -173,27 +172,51 @@ export class UpdateService extends ConsoleLogger {
}; };
} }
this.log(`Time used: ${moment().diff(clock, 'seconds')} s`); this.log(`Time used: ${moment().diff(clock, 'seconds')} s`);
/*clock = moment();
this.log('part ex');
const archiveIds: number[] = (
await this.db
.createQueryBuilder()
.select('distinct(file.archiveId)', 'archiveId')
.from(ArchiveFile, 'file')
.where('file.path = any(:requestedFiles)', { requestedFiles: requestedFiles })
.innerJoin('file.archive', 'archive')
.andWhere('archive.buildId = :buildId', { buildId: build.id })
.getRawMany()
).map((obj) => obj.archiveId);
this.log(`Time used: ${moment().diff(clock, 'seconds')} s`);*/
clock = moment(); clock = moment();
this.log('part 2'); this.log('part 2');
const allPartArchives = await this.getArchives(id, depotDto, version, (qb) => const allPartArchivesQuery = this.db
qb .getRepository(Archive)
.andWhere( .createQueryBuilder('archive')
`exists ${qb .where('archive.buildId = :buildId', { buildId: build.id })
.subQuery() .andWhere('archive.role = :partRole', { partRole: ArchiveType.Part });
.select('file.path') //.innerJoin('archive.containingFiles', 'file')
.from(ArchiveFile, 'file') //.andWhere('file.path = any(:requestedFiles)', { requestedFiles: requestedFiles });
.where('file.archiveId = archive.id')
.andWhere('file.path = any(:requestedFiles)', { requestedFiles: requestedFiles }) allPartArchivesQuery.andWhere(
.getQuery()}` `exists ${allPartArchivesQuery
) .subQuery()
.andWhere('archive.role = :partRole', { partRole: ArchiveType.Part }) .select('file.path')
.from(ArchiveFile, 'file')
.where('file.archiveId = archive.id')
.andWhere('file.path = any(:requestedFiles)', { requestedFiles: requestedFiles })
.getQuery()}`
); );
const allPartArchives = await allPartArchivesQuery.getMany();
this.log(`Time used: ${moment().diff(clock, 'seconds')} s`); this.log(`Time used: ${moment().diff(clock, 'seconds')} s`);
clock = moment(); clock = moment();
this.log('part 3'); this.log('part 3');
const [fullArchive] = await this.getArchives(id, depotDto, version, (qb) => const fullArchive = await this.db
qb.andWhere('archive.role = :fullRole', { fullRole: ArchiveType.Full }) .getRepository(Archive)
); .createQueryBuilder('archive')
.where('archive.buildId = :buildId', { buildId: build.id })
.andWhere('archive.role = :fullRole', { fullRole: ArchiveType.Full })
.limit(1)
.getOne();
let archives = allPartArchives; let archives = allPartArchives;
if (fullArchive && this.getCostOfArchives([fullArchive]) <= this.getCostOfArchives(allPartArchives)) { if (fullArchive && this.getCostOfArchives([fullArchive]) <= this.getCostOfArchives(allPartArchives)) {
archives = [fullArchive]; archives = [fullArchive];
......
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