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
6ca2bca0
Commit
6ca2bca0
authored
Apr 29, 2019
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix CodeReuse/ActiveRecord violation
parent
82e15524
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
42 deletions
+54
-42
ee/app/finders/geo/job_artifact_registry_finder.rb
ee/app/finders/geo/job_artifact_registry_finder.rb
+15
-42
ee/app/models/geo/fdw/ci/job_artifact.rb
ee/app/models/geo/fdw/ci/job_artifact.rb
+31
-0
ee/app/models/geo/job_artifact_registry.rb
ee/app/models/geo/job_artifact_registry.rb
+8
-0
No files found.
ee/app/finders/geo/job_artifact_registry_finder.rb
View file @
6ca2bca0
...
...
@@ -84,7 +84,7 @@ module Geo
def
find_retryable_failed_registries
(
batch_size
:,
except_artifact_ids:
[])
find_failed_registries
.
retry_due
.
where
.
not
(
artifact_id:
except_artifact_ids
)
.
artifact_id_not_in
(
except_artifact_ids
)
.
limit
(
batch_size
)
end
# rubocop: enable CodeReuse/ActiveRecord
...
...
@@ -93,7 +93,7 @@ module Geo
def
find_retryable_synced_missing_on_primary_registries
(
batch_size
:,
except_artifact_ids:
[])
find_synced_missing_on_primary_registries
.
retry_due
.
where
.
not
(
artifact_id:
except_artifact_ids
)
.
artifact_id_not_in
(
except_artifact_ids
)
.
limit
(
batch_size
)
end
# rubocop: enable CodeReuse/ActiveRecord
...
...
@@ -154,67 +154,45 @@ module Geo
Geo
::
JobArtifactRegistry
.
failed
end
#
# FDW accessors
#
# rubocop: disable CodeReuse/ActiveRecord
def
fdw_find
job_artifacts
.
joins
(
"INNER JOIN job_artifact_registry ON job_artifact_registry.artifact_id =
#{
fdw_table
}
.id"
)
job_artifacts
.
inner_join_job_artifact_registry
.
geo_syncable
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
fdw_find_unsynced
(
except_artifact_ids
:)
job_artifacts
.
joins
(
"LEFT OUTER JOIN job_artifact_registry
ON job_artifact_registry.artifact_id =
#{
fdw_table
}
.id"
)
job_artifacts
.
missing_job_artifact_registry
.
geo_syncable
.
where
(
job_artifact_registry:
{
artifact_id:
nil
})
.
where
.
not
(
id:
except_artifact_ids
)
.
id_not_in
(
except_artifact_ids
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
fdw_find_migrated_local
(
except_artifact_ids
:)
job_artifacts
.
joins
(
"INNER JOIN job_artifact_registry ON job_artifact_registry.artifact_id =
#{
fdw_table
}
.id"
)
job_artifacts
.
inner_join_job_artifact_registry
.
with_files_stored_remotely
.
where
.
not
(
id:
except_artifact_ids
)
.
id_not_in
(
except_artifact_ids
)
.
merge
(
Geo
::
JobArtifactRegistry
.
all
)
end
# rubocop: enable CodeReuse/ActiveRecord
def
fdw_table
Geo
::
Fdw
::
Ci
::
JobArtifact
.
table_name
end
#
# Legacy accessors (non FDW)
#
# rubocop: disable CodeReuse/ActiveRecord
def
legacy_find_synced
legacy_inner_join_registry_ids
(
syncable
,
find_synced_registries
.
pluck
(
:artifact_id
)
,
find_synced_registries
.
pluck
_artifact_key
,
Ci
::
JobArtifact
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
legacy_find_failed
legacy_inner_join_registry_ids
(
syncable
,
find_failed_registries
.
pluck
(
:artifact_id
)
,
find_failed_registries
.
pluck
_artifact_key
,
Ci
::
JobArtifact
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
legacy_find_unsynced
(
except_artifact_ids
:)
registry_artifact_ids
=
Geo
::
JobArtifactRegistry
.
pluck
(
:artifact_id
)
|
except_artifact_ids
registry_artifact_ids
=
Geo
::
JobArtifactRegistry
.
pluck
_artifact_key
|
except_artifact_ids
legacy_left_outer_join_registry_ids
(
syncable
,
...
...
@@ -222,11 +200,9 @@ module Geo
Ci
::
JobArtifact
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
legacy_find_migrated_local
(
except_artifact_ids
:)
registry_artifact_ids
=
Geo
::
JobArtifactRegistry
.
pluck
(
:artifact_id
)
-
except_artifact_ids
registry_artifact_ids
=
Geo
::
JobArtifactRegistry
.
pluck
_artifact_key
-
except_artifact_ids
legacy_inner_join_registry_ids
(
legacy_finder
.
job_artifacts
.
with_files_stored_remotely
,
...
...
@@ -234,16 +210,13 @@ module Geo
Ci
::
JobArtifact
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
legacy_find_synced_missing_on_primary
legacy_inner_join_registry_ids
(
syncable
,
find_synced_missing_on_primary_registries
.
pluck
(
:artifact_id
)
,
find_synced_missing_on_primary_registries
.
pluck
_artifact_key
,
Ci
::
JobArtifact
)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
ee/app/models/geo/fdw/ci/job_artifact.rb
View file @
6ca2bca0
...
...
@@ -15,6 +15,37 @@ module Geo
scope
:not_expired
,
->
{
where
(
'expire_at IS NULL OR expire_at > ?'
,
Time
.
current
)
}
scope
:geo_syncable
,
->
{
with_files_stored_locally
.
not_expired
}
scope
:project_id_in
,
->
(
ids
)
{
joins
(
:project
).
merge
(
Geo
::
Fdw
::
Project
.
id_in
(
ids
))
}
class
<<
self
def
inner_join_job_artifact_registry
join_statement
=
arel_table
.
join
(
job_artifact_registry_table
,
Arel
::
Nodes
::
InnerJoin
)
.
on
(
arel_table
[
:id
].
eq
(
job_artifact_registry_table
[
:artifact_id
]))
joins
(
join_statement
.
join_sources
)
end
def
missing_job_artifact_registry
left_outer_join_job_artifact_registry
.
where
(
job_artifact_registry_table
[
:id
].
eq
(
nil
))
end
private
def
job_artifact_registry_table
Geo
::
JobArtifactRegistry
.
arel_table
end
def
left_outer_join_job_artifact_registry
join_statement
=
arel_table
.
join
(
job_artifact_registry_table
,
Arel
::
Nodes
::
OuterJoin
)
.
on
(
arel_table
[
:id
].
eq
(
job_artifact_registry_table
[
:artifact_id
]))
joins
(
join_statement
.
join_sources
)
end
end
end
end
end
...
...
ee/app/models/geo/job_artifact_registry.rb
View file @
6ca2bca0
...
...
@@ -2,4 +2,12 @@
class
Geo::JobArtifactRegistry
<
Geo
::
BaseRegistry
include
Geo
::
Syncable
def
self
.
artifact_id_not_in
(
ids
)
where
.
not
(
artifact_id:
ids
)
end
def
self
.
pluck_artifact_key
where
(
nil
).
pluck
(
:artifact_id
)
end
end
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