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
30cad942
Commit
30cad942
authored
Jul 25, 2025
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove archive for non-existing
parent
4800f047
Pipeline
#39485
passed with stages
in 1 minute and 18 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
6 deletions
+39
-6
console-api/src/app.service.ts
console-api/src/app.service.ts
+22
-6
console-api/src/s3/s3.service.ts
console-api/src/s3/s3.service.ts
+17
-0
No files found.
console-api/src/app.service.ts
View file @
30cad942
import
{
Connection
,
IsNull
,
Not
,
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
Connection
,
I
n
,
I
sNull
,
Not
,
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
InjectConnection
}
from
'
@nestjs/typeorm
'
;
import
{
ConsoleLogger
,
forwardRef
,
Inject
,
Injectable
}
from
'
@nestjs/common
'
;
import
{
AppsJson
}
from
'
./utility/apps-json-type
'
;
...
...
@@ -264,7 +264,8 @@ export class AppService extends ConsoleLogger {
.
createQueryBuilder
(
'
unusedBuild
'
)
.
select
(
'
distinct(archive.path)
'
,
'
pathToPurge
'
)
.
innerJoin
(
'
unusedBuild.archives
'
,
'
archive
'
)
.
where
(
'
archive.role != :latestRole
'
,
{
latestRole
:
ArchiveType
.
Full
});
.
where
(
'
archive.role != :fullRole
'
,
{
fullRole
:
ArchiveType
.
Full
})
.
andWhere
(
'
archive.role != :fullsRole
'
,
{
fullsRole
:
ArchiveType
.
Fulls
});
const
subQuery
=
query
.
subQuery
()
...
...
@@ -283,7 +284,7 @@ export class AppService extends ConsoleLogger {
query
.
andWhere
(
`unusedBuild.id not in
${
subQuery
.
getQuery
()}
`
).
andWhere
(
`not exists
${
packageReferenceQuery
.
getQuery
()}
`
);
// this.log(`SQL: ${query.getQueryAndParameters()}`);
return
(
await
query
.
getRawMany
()).
map
((
s
)
=>
`
${
s
.
pathToPurge
}
.tar.zst`
as
string
);
return
(
await
query
.
getRawMany
()).
map
((
s
)
=>
s
.
pathToPurge
as
string
);
}
private
async
getArchivePathsToPurge
(
buildId
:
number
)
{
...
...
@@ -295,7 +296,20 @@ export class AppService extends ConsoleLogger {
this
.
packageReferenceSubQuery
(
query
);
// this.log(`SQL: ${query.getQueryAndParameters()}`);
return
(
await
query
.
getRawMany
()).
map
((
s
)
=>
`
${
s
.
pathToPurge
}
.tar.zst`
as
string
);
return
(
await
query
.
getRawMany
()).
map
((
s
)
=>
s
.
pathToPurge
as
string
);
}
private
async
removeArchiveEntry
(
paths
:
string
[])
{
if
(
!
paths
||
!
paths
.
length
)
{
return
;
}
const
chunks
=
_
.
chunk
(
paths
,
65000
);
await
this
.
db
.
transaction
(
async
(
edb
)
=>
{
for
(
const
chunk
of
chunks
)
{
this
.
log
(
`Removing archive entries for
${
chunk
.
length
}
paths.`
);
await
edb
.
getRepository
(
Archive
).
delete
({
path
:
In
(
chunk
)
});
}
});
}
async
purgeOldArchives
()
{
...
...
@@ -304,7 +318,8 @@ export class AppService extends ConsoleLogger {
if
(
!
paths
.
length
)
{
return
;
}
return
this
.
packageS3
.
removeObjects
(
paths
);
await
this
.
packageS3
.
removeObjects
(
paths
.
map
((
p
)
=>
p
+
'
.tar.zst
'
));
await
this
.
removeArchiveEntry
(
paths
);
}
private
async
purgeRelatedArchives
(
build
:
Build
)
{
...
...
@@ -313,7 +328,8 @@ export class AppService extends ConsoleLogger {
if
(
!
paths
.
length
)
{
return
;
}
return
this
.
packageS3
.
removeObjects
(
paths
);
await
this
.
packageS3
.
removeObjects
(
paths
.
map
((
p
)
=>
p
+
'
.tar.zst
'
));
await
this
.
removeArchiveEntry
(
paths
);
}
async
removeBuild
(
user
:
MyCardUser
,
id
:
string
,
depotDto
:
DepotDto
,
version
:
string
)
{
...
...
console-api/src/s3/s3.service.ts
View file @
30cad942
...
...
@@ -72,6 +72,23 @@ export class S3Service extends ConsoleLogger {
return
this
.
s3
.
send
(
command
);
}
async
hasObject
(
path
:
string
)
{
try
{
await
this
.
s3
.
send
(
new
HeadObjectCommand
({
Bucket
:
this
.
bucket
,
Key
:
this
.
getPathWithPrefix
(
path
),
})
);
return
true
;
}
catch
(
e
)
{
if
(
e
.
name
===
'
NotFound
'
)
{
return
false
;
}
throw
e
;
// rethrow other errors
}
}
async
removeObjects
(
paths
:
string
[])
{
const
CHUNK_SIZE
=
1000
;
...
...
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