Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
console
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
console
Commits
46c72c45
Commit
46c72c45
authored
Aug 04, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better packager system
parent
dfb739a7
Pipeline
#15363
passed with stages
in 5 minutes and 58 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
30 deletions
+37
-30
console-api/src/update/update.service.ts
console-api/src/update/update.service.ts
+37
-30
No files found.
console-api/src/update/update.service.ts
View file @
46c72c45
...
...
@@ -209,26 +209,29 @@ export class UpdateService extends ConsoleLogger {
if
(
!
requestedFiles
||
!
requestedFiles
.
length
)
{
throw
new
BlankReturnMessageDto
(
400
,
'
empty files
'
).
toException
();
}
const
requestedFilesSet
=
new
Set
(
requestedFiles
);
const
build
=
await
this
.
getBuild
(
id
,
depotDto
,
version
,
(
qb
)
=>
qb
.
select
(
'
build.id
'
));
console
.
log
(
1
);
const
bestUpdateArchive
=
await
this
.
db
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
})
.
andWhere
(
'
:requestedFiles @> archive.files
'
,
{
requestedFiles
})
.
orderBy
(
'
array_length(archive.files, 1)
'
,
'
DESC
'
)
.
take
(
1
)
.
getOne
();
.
getMany
();
const
suitableUpdateArchives
=
updateArchives
.
filter
((
a
)
=>
a
.
files
.
every
((
f
)
=>
requestedFilesSet
.
has
(
f
)));
let
bestUpdateArchive
:
Archive
;
if
(
suitableUpdateArchives
.
length
)
{
bestUpdateArchive
=
_
.
maxBy
(
suitableUpdateArchives
,
(
a
)
=>
a
.
files
.
length
);
}
console
.
log
(
1.5
);
let
remainingFiles
:
string
[];
if
(
bestUpdateArchive
)
{
// console.log(`Found best update archive: ${bestUpdateArchive}`);
const
exactFiles
=
new
Set
(
bestUpdateArchive
.
files
);
remainingFiles
=
requestedFiles
.
filter
((
f
)
=>
!
exactFiles
.
has
(
f
));
// If single update archive satisfies all requested files, return it.
if
(
!
remainingFiles
.
length
)
{
// console.log('exact', bestUpdateArchive);
await
this
.
mirror
.
lookForArchivesMirror
([
bestUpdateArchive
]);
return
{
cdnUrl
:
this
.
cdnUrl
,
...
...
@@ -238,8 +241,7 @@ export class UpdateService extends ConsoleLogger {
}
const
packagePlans
:
Archive
[][]
=
[];
console
.
log
(
2
);
const
allPossiblePartArchives
=
await
this
.
db
const
partArchives
=
await
this
.
db
.
getRepository
(
Archive
)
.
createQueryBuilder
(
'
archive
'
)
.
select
([
'
archive.hash
'
,
'
archive.path
'
,
'
archive.size
'
,
'
archive.files
'
])
...
...
@@ -248,40 +250,45 @@ export class UpdateService extends ConsoleLogger {
.
getMany
();
// Plan 1: use all part archives
cons
ole
.
log
(
3
);
const
allPartArchives
=
this
.
pickArchives
(
allPossiblePartArchives
,
requestedFiles
);
if
(
allPartArchives
.
length
)
{
packagePlans
.
push
(
all
PartArchives
);
cons
t
suitablePartArchives
=
this
.
pickArchives
(
partArchives
,
requestedFiles
);
if
(
suitablePartArchives
.
length
)
{
// console.log(`1 ${suitablePartArchives}`);
packagePlans
.
push
(
suitable
PartArchives
);
}
// Plan 2: use a smallest single as-large-possible archive
console
.
log
(
4
);
const
smallestSingleArchive
=
await
this
.
db
.
getRepository
(
Archive
)
.
createQueryBuilder
(
'
archive
'
)
.
select
([
'
archive.hash
'
,
'
archive.path
'
,
'
archive.size
'
])
.
where
(
'
archive.buildId = :buildId
'
,
{
buildId
:
build
.
id
})
.
andWhere
(
'
archive.role != :partRole
'
,
{
partRole
:
ArchiveType
.
Part
})
.
andWhere
(
'
archive.files @> :requestedFiles
'
,
{
requestedFiles
})
.
orderBy
(
'
archive.size
'
,
'
ASC
'
)
.
limit
(
1
)
.
getOne
();
if
(
smallestSingleArchive
)
{
packagePlans
.
push
([
smallestSingleArchive
]);
const
satisfyingUpdateArchives
=
updateArchives
.
filter
((
a
)
=>
{
const
files
=
new
Set
(
a
.
files
);
return
requestedFiles
.
every
((
f
)
=>
files
.
has
(
f
));
});
if
(
satisfyingUpdateArchives
.
length
)
{
const
useArchive
=
_
.
minBy
(
satisfyingUpdateArchives
,
(
a
)
=>
a
.
size
);
// 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
]);
}
if
(
bestUpdateArchive
)
{
console
.
log
(
5
);
// Plan 3: use single update archive + part archives for remaining files
const
remainingPartArchives
=
this
.
pickArchives
(
allPossibleP
artArchives
,
remainingFiles
);
const
remainingPartArchives
=
this
.
pickArchives
(
p
artArchives
,
remainingFiles
);
if
(
remainingPartArchives
.
length
)
{
packagePlans
.
push
([
bestUpdateArchive
,
...
remainingPartArchives
]);
// console.log(`3 ${bestUpdateArchive} ${remainingPartArchives}`);
}
}
console
.
log
(
6
);
const
archives
=
_
.
minBy
(
packagePlans
,
(
plan
)
=>
this
.
getCostOfArchives
(
plan
));
console
.
log
(
archives
);
// console.log('use',
archives);
await
this
.
mirror
.
lookForArchivesMirror
(
archives
);
return
{
cdnUrl
:
this
.
cdnUrl
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment