Commit c1fdf5ca authored by nanahira's avatar nanahira

add fulls

parent 6158e200
......@@ -8,6 +8,7 @@ export enum ArchiveType {
Full = 'full',
Update = 'update',
Part = 'part',
Fulls = 'fulls',
}
@Entity()
......
......@@ -10,8 +10,8 @@ import { PackageS3Service } from '../package-s3/package-s3.service';
import _ from 'lodash';
import { AppsJson } from '../utility/apps-json-type';
import { MirrorService } from '../mirror/mirror.service';
import Platform = AppsJson.Platform;
import moment from 'moment';
import Platform = AppsJson.Platform;
@Injectable()
export class UpdateService extends ConsoleLogger {
......@@ -159,9 +159,14 @@ export class UpdateService extends ConsoleLogger {
}
async getFullPackageMetalink(id: string, depotDto: DepotDto, version: string, ip: string) {
const archives = await this.getArchives(id, depotDto, version, (qb) =>
qb.select(['archive.hash', 'archive.path', 'archive.size']).andWhere('archive.role = :fullRole', { fullRole: ArchiveType.Full })
);
const tryRole = (role: ArchiveType) =>
this.getArchives(id, depotDto, version, (qb) =>
qb.select(['archive.hash', 'archive.path', 'archive.size']).andWhere('archive.role = :fullRole', { fullRole: ArchiveType.Full })
);
let archives = await tryRole(ArchiveType.Fulls);
if (!archives.length) {
archives = await tryRole(ArchiveType.Full);
}
await this.mirror.lookForArchivesMirror(archives, ip);
archives.forEach((a) => a.fillUrl(this.cdnUrl, this.cdnUrlOversize));
return {
......@@ -231,13 +236,16 @@ export class UpdateService extends ConsoleLogger {
}
const requestedFilesSet = new Set(requestedFiles);
const build = await this.getBuild(id, depotDto, version, (qb) => qb.select('build.id'));
const updateArchives = await this.db
.getRepository(Archive)
.createQueryBuilder('archive')
.select(['archive.hash', 'archive.path', 'archive.size', 'archive.files'])
.where('archive.buildId = :buildId', { buildId: build.id })
.andWhere('archive.role = :updateRole', { updateRole: ArchiveType.Update })
.getMany();
const getArchiveQuery = (role: ArchiveType) =>
this.db
.getRepository(Archive)
.createQueryBuilder('archive')
.select(['archive.hash', 'archive.path', 'archive.size', 'archive.files'])
.where('archive.buildId = :buildId', { buildId: build.id })
.andWhere('archive.role = :role', { role });
const getArchives = (role: ArchiveType) => getArchiveQuery(role).getMany();
const getSingleArchive = (role: ArchiveType) => getArchiveQuery(role).limit(1).getOneOrFail();
const updateArchives = await getArchives(ArchiveType.Update);
const suitableUpdateArchives = updateArchives.filter((a) => a.files.every((f) => requestedFilesSet.has(f)));
let bestUpdateArchive: Archive;
if (suitableUpdateArchives.length) {
......@@ -251,7 +259,7 @@ export class UpdateService extends ConsoleLogger {
remainingFiles = requestedFiles.filter((f) => !exactFiles.has(f));
// If single update archive satisfies all requested files, return it.
if (!remainingFiles.length) {
// console.log('exact', bestUpdateArchive);
// console.log('exact', bestUpdateArchive);updateArchives
await this.mirror.lookForArchivesMirror([bestUpdateArchive], ip);
bestUpdateArchive.fillUrl(this.cdnUrl, this.cdnUrlOversize);
return {
......@@ -261,13 +269,7 @@ export class UpdateService extends ConsoleLogger {
}
const packagePlans: Archive[][] = [];
const partArchives = await this.db
.getRepository(Archive)
.createQueryBuilder('archive')
.select(['archive.hash', 'archive.path', 'archive.size', 'archive.files'])
.where('archive.buildId = :buildId', { buildId: build.id })
.andWhere('archive.role = :partRole', { partRole: ArchiveType.Part })
.getMany();
const partArchives = await getArchives(ArchiveType.Part);
// Plan 1: use all part archives
const suitablePartArchives = this.pickArchives(partArchives, requestedFiles);
......@@ -286,16 +288,15 @@ export class UpdateService extends ConsoleLogger {
// console.log(`2 update ${useArchive}`);
packagePlans.push([useArchive]);
} else {
const fullArchive = await this.db
.getRepository(Archive)
.createQueryBuilder('archive')
.select(['archive.hash', 'archive.path', 'archive.size'])
.where('archive.buildId = :buildId', { buildId: build.id })
.andWhere('archive.role = :fullRole', { fullRole: ArchiveType.Full })
.limit(1)
.getOneOrFail();
// console.log(`2 full ${fullArchive}`);
packagePlans.push([fullArchive]);
const fullsArchives = await getArchives(ArchiveType.Fulls);
if (fullsArchives.length) {
const suitableFulls = this.pickArchives(fullsArchives, requestedFiles);
packagePlans.push(suitableFulls?.length ? suitableFulls : fullsArchives);
} else {
const fullArchive = await getSingleArchive(ArchiveType.Full);
// console.log(`2 full ${fullArchive}`);
packagePlans.push([fullArchive]);
}
}
if (bestUpdateArchive) {
......
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