Commit 8c7335f8 authored by nanahira's avatar nanahira

tmp clock

parent 1b6e065e
Pipeline #4931 passed with stage
in 4 minutes and 3 seconds
import { Entity, ManyToOne, PrimaryColumn } from 'typeorm';
import { Entity, Index, ManyToOne, PrimaryColumn } from 'typeorm';
import { Archive } from './Archive.entity';
@Entity()
......@@ -6,6 +6,7 @@ export class ArchiveFile {
@ManyToOne(() => Archive, (a) => a.containingFiles, { primary: true, onDelete: 'CASCADE' })
archive: Archive;
@Index()
@PrimaryColumn('varchar', { length: 256 })
path: string;
......
......@@ -8,6 +8,9 @@ import { BlankReturnMessageDto } from '../dto/ReturnMessage.dto';
import { Archive, ArchiveType } from '../entities/Archive.entity';
import { PackageS3Service } from '../package-s3/package-s3.service';
import _ from 'lodash';
import { ArchiveFile } from '../entities/ArchiveFile.entity';
import * as os from 'os';
import moment from 'moment';
@Injectable()
export class UpdateService extends ConsoleLogger {
......@@ -135,6 +138,8 @@ export class UpdateService extends ConsoleLogger {
}
async getPartPackageMetalink(id: string, depotDto: DepotDto, version: string, requestedFiles: string[]) {
let clock = moment();
this.log('part 1');
const tryExactArchives = await this.getArchives(
id,
depotDto,
......@@ -142,7 +147,21 @@ export class UpdateService extends ConsoleLogger {
(qb) =>
qb
.andWhere('archive.role != :partRole', { partRole: ArchiveType.Part })
.andWhere(':requestedFiles = archive.files', { requestedFiles: requestedFiles })
/*.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
......@@ -153,11 +172,25 @@ export class UpdateService extends ConsoleLogger {
archives: tryExactArchives,
};
}
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(':requestedFiles && archive.files', { requestedFiles: requestedFiles })
.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 })
);
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 })
);
......@@ -165,6 +198,7 @@ export class UpdateService extends ConsoleLogger {
if (fullArchive && this.getCostOfArchives([fullArchive]) <= this.getCostOfArchives(allPartArchives)) {
archives = [fullArchive];
}
this.log(`Time used: ${moment().diff(clock, 'seconds')} s`);
return {
cdnUrl: this.cdnUrl,
archives,
......
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