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
dfb739a7
Commit
dfb739a7
authored
Aug 04, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
too slow
parent
c56eb3b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
25 deletions
+56
-25
console-api/src/update/update.service.ts
console-api/src/update/update.service.ts
+56
-25
No files found.
console-api/src/update/update.service.ts
View file @
dfb739a7
...
...
@@ -36,11 +36,7 @@ export class UpdateService extends ConsoleLogger {
if
(
platform
===
'
generic
'
)
{
continue
;
}
/*const depotDto = new DepotDto();
depotDto.locale = 'generic';
depotDto.arch = 'generic';
depotDto.platform = platform;*/
// this.log(platform);
for
(
const
app
of
data
)
{
app
.
version
??
=
{};
const
tryCache
=
appVersionCacheMap
.
get
(
app
.
id
);
...
...
@@ -199,10 +195,11 @@ export class UpdateService extends ConsoleLogger {
const
result
=
new
Set
<
Archive
>
();
for
(
const
file
of
requestedFiles
)
{
try
{
result
.
add
(
aset
.
find
((
a
)
=>
a
.
files
.
has
(
file
)).
archive
);
}
catch
(
e
)
{
//throw new BlankReturnMessageDto(404, `File ${file} not found in archives.`).toException();
const
satisfyingArchive
=
aset
.
find
((
a
)
=>
a
.
files
.
has
(
file
))?.
archive
;
if
(
satisfyingArchive
)
{
result
.
add
(
satisfyingArchive
);
}
else
{
// Ignore missing file for now
}
}
return
Array
.
from
(
result
);
...
...
@@ -213,22 +210,35 @@ export class UpdateService extends ConsoleLogger {
throw
new
BlankReturnMessageDto
(
400
,
'
empty files
'
).
toException
();
}
const
build
=
await
this
.
getBuild
(
id
,
depotDto
,
version
,
(
qb
)
=>
qb
.
select
(
'
build.id
'
));
const
tryExactArchiveQuery
=
this
.
db
console
.
log
(
1
);
const
bestUpdateArchive
=
await
this
.
db
.
getRepository
(
Archive
)
.
createQueryBuilder
(
'
archive
'
)
.
select
([
'
archive.hash
'
,
'
archive.path
'
,
'
archive.size
'
])
.
select
([
'
archive.hash
'
,
'
archive.path
'
,
'
archive.size
'
,
'
archive.files
'
])
.
where
(
'
archive.buildId = :buildId
'
,
{
buildId
:
build
.
id
})
.
andWhere
(
'
archive.role != :partRole
'
,
{
partRole
:
ArchiveType
.
Part
})
.
andWhere
(
'
:requestedFiles = archive.files
'
,
{
requestedFiles
})
.
limit
(
1
);
const
tryExactArchives
=
await
tryExactArchiveQuery
.
getMany
();
if
(
tryExactArchives
.
length
)
{
return
{
cdnUrl
:
this
.
cdnUrl
,
archives
:
tryExactArchives
,
};
.
andWhere
(
'
archive.role = :updateRole
'
,
{
updateRole
:
ArchiveType
.
Update
})
.
andWhere
(
'
:requestedFiles @> archive.files
'
,
{
requestedFiles
})
.
orderBy
(
'
array_length(archive.files, 1)
'
,
'
DESC
'
)
.
take
(
1
)
.
getOne
();
console
.
log
(
1.5
);
let
remainingFiles
:
string
[];
if
(
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
)
{
await
this
.
mirror
.
lookForArchivesMirror
([
bestUpdateArchive
]);
return
{
cdnUrl
:
this
.
cdnUrl
,
archives
:
[
bestUpdateArchive
],
};
}
}
const
packagePlans
:
Archive
[][]
=
[];
console
.
log
(
2
);
const
allPossiblePartArchives
=
await
this
.
db
.
getRepository
(
Archive
)
.
createQueryBuilder
(
'
archive
'
)
...
...
@@ -237,20 +247,41 @@ export class UpdateService extends ConsoleLogger {
.
andWhere
(
'
archive.role = :partRole
'
,
{
partRole
:
ArchiveType
.
Part
})
.
getMany
();
// Plan 1: use all part archives
console
.
log
(
3
);
const
allPartArchives
=
this
.
pickArchives
(
allPossiblePartArchives
,
requestedFiles
);
const
fullArchive
=
await
this
.
db
if
(
allPartArchives
.
length
)
{
packagePlans
.
push
(
allPartArchives
);
}
// 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 = :fullRole
'
,
{
fullRole
:
ArchiveType
.
Full
})
.
andWhere
(
'
archive.role != :partRole
'
,
{
partRole
:
ArchiveType
.
Part
})
.
andWhere
(
'
archive.files @> :requestedFiles
'
,
{
requestedFiles
})
.
orderBy
(
'
archive.size
'
,
'
ASC
'
)
.
limit
(
1
)
.
getOne
();
if
(
smallestSingleArchive
)
{
packagePlans
.
push
([
smallestSingleArchive
]);
}
let
archives
=
allPartArchives
;
if
(
!
allPartArchives
.
length
||
(
fullArchive
&&
this
.
getCostOfArchives
([
fullArchive
])
<=
this
.
getCostOfArchives
(
allPartArchives
)))
{
archives
=
[
fullArchive
];
if
(
bestUpdateArchive
)
{
console
.
log
(
5
);
// Plan 3: use single update archive + part archives for remaining files
const
remainingPartArchives
=
this
.
pickArchives
(
allPossiblePartArchives
,
remainingFiles
);
if
(
remainingPartArchives
.
length
)
{
packagePlans
.
push
([
bestUpdateArchive
,
...
remainingPartArchives
]);
}
}
console
.
log
(
6
);
const
archives
=
_
.
minBy
(
packagePlans
,
(
plan
)
=>
this
.
getCostOfArchives
(
plan
));
console
.
log
(
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