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 { ...@@ -97,19 +97,13 @@ export class UpdateService extends ConsoleLogger {
}; };
} }
/*
private getPartArchiveSubset( private getPartArchiveSubset(
requestedFiles: string[], requestedFiles: string[],
allArchives: Archive[], allArchives: Archive[],
currentSize = 0, currentSize = 0,
currentBestSolutionValue = Infinity currentBestSolutionValue = Infinity
): [Archive[], number] { ): [Archive[], number] {
/*
this.log(
`requested: ${requestedFiles.join(',')} remaining: ${allArchives
.map((a) => `${a.size}:${a.files.join(',')}`)
.join('|')} currentSize: ${currentSize} currentBestSolutionValue: ${currentBestSolutionValue}`
);
*/
if (!requestedFiles.length) { if (!requestedFiles.length) {
return [[], currentSize]; return [[], currentSize];
} }
...@@ -132,6 +126,13 @@ export class UpdateService extends ConsoleLogger { ...@@ -132,6 +126,13 @@ export class UpdateService extends ConsoleLogger {
} }
return bestSolution; 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[]) { async getPartPackageMetalink(id: string, depotDto: DepotDto, version: string, requestedFiles: string[]) {
const tryExactArchives = await this.getArchives( const tryExactArchives = await this.getArchives(
...@@ -152,15 +153,17 @@ export class UpdateService extends ConsoleLogger { ...@@ -152,15 +153,17 @@ export class UpdateService extends ConsoleLogger {
archives: tryExactArchives, archives: tryExactArchives,
}; };
} }
const allArchives = await this.getArchives(id, depotDto, version, (qb) => const allPartArchives = await this.getArchives(id, depotDto, version, (qb) =>
qb.andWhere(':requestedFiles && archive.files', { requestedFiles: requestedFiles }).orderBy('archive.size', 'ASC') 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) { let archives = allPartArchives;
archive.files = _.intersection(archive.files, requestedFiles); if (fullArchive && this.getCostOfArchives([fullArchive]) <= this.getCostOfArchives(allPartArchives)) {
}*/ archives = [fullArchive];
const [archives] = this.getPartArchiveSubset(_.uniq(requestedFiles), allArchives);
if (!archives) {
throw new BlankReturnMessageDto(404, 'Some files of this build not found').toException();
} }
return { return {
cdnUrl: this.cdnUrl, 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