Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ccea8498
Commit
ccea8498
authored
Nov 10, 2021
by
drew cimino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move AR querying logic into AR models
parent
8f35a038
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
4 deletions
+10
-4
app/models/ci/build.rb
app/models/ci/build.rb
+1
-0
app/models/ci/job_artifact.rb
app/models/ci/job_artifact.rb
+5
-0
app/services/ci/job_artifacts/destroy_all_expired_service.rb
app/services/ci/job_artifacts/destroy_all_expired_service.rb
+4
-4
No files found.
app/models/ci/build.rb
View file @
ccea8498
...
...
@@ -164,6 +164,7 @@ module Ci
scope
:with_artifacts_not_expired
,
->
{
with_downloadable_artifacts
.
where
(
'artifacts_expire_at IS NULL OR artifacts_expire_at > ?'
,
Time
.
current
)
}
scope
:with_expired_artifacts
,
->
{
with_downloadable_artifacts
.
where
(
'artifacts_expire_at < ?'
,
Time
.
current
)
}
scope
:with_pipeline_locked_artifacts
,
->
{
joins
(
:pipeline
).
where
(
'pipeline.locked'
:
Ci
::
Pipeline
.
lockeds
[
:artifacts_locked
])
}
scope
:last_month
,
->
{
where
(
'created_at > ?'
,
Date
.
today
-
1
.
month
)
}
scope
:manual_actions
,
->
{
where
(
when: :manual
,
status:
COMPLETED_STATUSES
+
%i[manual]
)
}
scope
:scheduled_actions
,
->
{
where
(
when: :delayed
,
status:
COMPLETED_STATUSES
+
%i[scheduled]
)
}
...
...
app/models/ci/job_artifact.rb
View file @
ccea8498
...
...
@@ -133,6 +133,7 @@ module Ci
scope
:not_expired
,
->
{
where
(
'expire_at IS NULL OR expire_at > ?'
,
Time
.
current
)
}
scope
:for_sha
,
->
(
sha
,
project_id
)
{
joins
(
job: :pipeline
).
where
(
ci_pipelines:
{
sha:
sha
,
project_id:
project_id
})
}
scope
:for_job_ids
,
->
(
job_ids
)
{
where
(
job_id:
job_ids
)
}
scope
:for_job_name
,
->
(
name
)
{
joins
(
:job
).
where
(
ci_builds:
{
name:
name
})
}
scope
:with_job
,
->
{
joins
(
:job
).
includes
(
:job
)
}
...
...
@@ -266,6 +267,10 @@ module Ci
self
.
where
(
project:
project
).
sum
(
:size
)
end
def
self
.
distinct_job_ids
distinct
.
pluck
(
:job_id
)
end
##
# FastDestroyAll concerns
# rubocop: disable CodeReuse/ServiceClass
...
...
app/services/ci/job_artifacts/destroy_all_expired_service.rb
View file @
ccea8498
...
...
@@ -54,19 +54,19 @@ module Ci
end
def
work_on_unknown_artifacts_backlog
build_ids
=
Ci
::
JobArtifact
.
expired_before
(
@start_at
).
artifact_unknown
.
distinct
.
limit
(
BATCH_SIZE
).
pluck
(
:job_id
)
build_ids
=
Ci
::
JobArtifact
.
expired_before
(
@start_at
).
artifact_unknown
.
limit
(
BATCH_SIZE
).
distinct_job_ids
return
false
unless
build_ids
.
present?
locked_pipeline_build_ids
=
::
Ci
::
Build
.
joins
(
:pipeline
).
where
(
id:
build_ids
,
:'pipeline.locked'
=>
Ci
::
Pipeline
.
lockeds
[
:artifacts_locked
]).
pluck
(
:id
)
unlocked_pipeline_build_ids
=
build_ids
-
locked_pipeline_build_ids
# IDs in memory
locked_pipeline_build_ids
=
::
Ci
::
Build
.
with_pipeline_locked_artifacts
.
id_in
(
build_ids
).
pluck_primary_key
unlocked_pipeline_build_ids
=
build_ids
-
locked_pipeline_build_ids
update_unknown_artifacts
(
locked_pipeline_build_ids
,
Ci
::
JobArtifact
.
lockeds
[
:artifacts_locked
])
||
update_unknown_artifacts
(
unlocked_pipeline_build_ids
,
Ci
::
JobArtifact
.
lockeds
[
:unlocked
])
end
def
update_unknown_artifacts
(
build_ids
,
locked_value
)
Ci
::
JobArtifact
.
where
(
job_id:
build_ids
).
update_all
(
locked:
locked_value
)
if
build_ids
.
any?
Ci
::
JobArtifact
.
for_job_ids
(
build_ids
).
update_all
(
locked:
locked_value
)
if
build_ids
.
any?
end
def
destroy_job_artifacts_with_slow_iteration
...
...
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