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