Commit a1b9cf9c authored by nanahira's avatar nanahira

too horrible for the shitty alg

parent 7c57f901
Pipeline #4875 passed with stages
in 1 minute and 15 seconds
......@@ -97,19 +97,13 @@ export class UpdateService extends ConsoleLogger {
};
}
/*
private getPartArchiveSubset(
requestedFiles: string[],
allArchives: Archive[],
currentSize = 0,
currentBestSolutionValue = Infinity
): [Archive[], number] {
/*
this.log(
`requested: ${requestedFiles.join(',')} remaining: ${allArchives
.map((a) => `${a.size}:${a.files.join(',')}`)
.join('|')} currentSize: ${currentSize} currentBestSolutionValue: ${currentBestSolutionValue}`
);
*/
if (!requestedFiles.length) {
return [[], currentSize];
}
......@@ -132,6 +126,13 @@ export class UpdateService extends ConsoleLogger {
}
return bestSolution;
}
*/
private getCostOfArchives(archives: Archive[]) {
const requestCost = archives.length * (0.05 / 10000);
const trafficCost = _.sumBy(archives, (a) => a.size) * (0.24 / 1024 ** 3);
return trafficCost + requestCost;
}
async getPartPackageMetalink(id: string, depotDto: DepotDto, version: string, requestedFiles: string[]) {
const tryExactArchives = await this.getArchives(
......@@ -152,15 +153,17 @@ export class UpdateService extends ConsoleLogger {
archives: tryExactArchives,
};
}
const allArchives = await this.getArchives(id, depotDto, version, (qb) =>
qb.andWhere(':requestedFiles && archive.files', { requestedFiles: requestedFiles }).orderBy('archive.size', 'ASC')
const allPartArchives = await this.getArchives(id, depotDto, version, (qb) =>
qb
.andWhere(':requestedFiles && archive.files', { requestedFiles: requestedFiles })
.andWhere('archive.role = :partRole', { partRole: ArchiveType.Part })
);
const [fullArchive] = await this.getArchives(id, depotDto, version, (qb) =>
qb.andWhere('archive.role = :fullRole', { fullRole: ArchiveType.Full })
);
/*for (const archive of allArchives) {
archive.files = _.intersection(archive.files, requestedFiles);
}*/
const [archives] = this.getPartArchiveSubset(_.uniq(requestedFiles), allArchives);
if (!archives) {
throw new BlankReturnMessageDto(404, 'Some files of this build not found').toException();
let archives = allPartArchives;
if (fullArchive && this.getCostOfArchives([fullArchive]) <= this.getCostOfArchives(allPartArchives)) {
archives = [fullArchive];
}
return {
cdnUrl: this.cdnUrl,
......
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