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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
9bb7c690
Commit
9bb7c690
authored
Oct 29, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix rubocop offenses.
parent
32666427
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
7 deletions
+9
-7
lib/gitlab/database/count.rb
lib/gitlab/database/count.rb
+5
-3
spec/lib/gitlab/database/count_spec.rb
spec/lib/gitlab/database/count_spec.rb
+4
-4
No files found.
lib/gitlab/database/count.rb
View file @
9bb7c690
...
@@ -40,7 +40,7 @@ module Gitlab
...
@@ -40,7 +40,7 @@ module Gitlab
if
strategy
.
enabled?
if
strategy
.
enabled?
models_with_missing_counts
=
models
-
counts_by_model
.
keys
models_with_missing_counts
=
models
-
counts_by_model
.
keys
return
counts_by_model
if
models_with_missing_counts
.
empty?
break
if
models_with_missing_counts
.
empty?
counts
=
strategy
.
new
(
models_with_missing_counts
).
count
counts
=
strategy
.
new
(
models_with_missing_counts
).
count
...
@@ -139,6 +139,7 @@ module Gitlab
...
@@ -139,6 +139,7 @@ module Gitlab
LEFT JOIN pg_stat_user_tables ON pg_class.relname = pg_stat_user_tables.relname
LEFT JOIN pg_stat_user_tables ON pg_class.relname = pg_stat_user_tables.relname
WHERE pg_class.relname IN (
#{
table_names
.
map
{
|
table
|
"'
#{
table
}
'"
}
.join(',')})
WHERE pg_class.relname IN (
#{
table_names
.
map
{
|
table
|
"'
#{
table
}
'"
}
.join(',')})
SQL
SQL
if
check_statistics
if
check_statistics
base_query
+
"AND (last_vacuum >
#{
time
}
OR last_autovacuum >
#{
time
}
OR last_analyze >
#{
time
}
OR last_autoanalyze >
#{
time
}
)"
base_query
+
"AND (last_vacuum >
#{
time
}
OR last_autovacuum >
#{
time
}
OR last_analyze >
#{
time
}
OR last_autoanalyze >
#{
time
}
)"
else
else
...
@@ -177,6 +178,7 @@ module Gitlab
...
@@ -177,6 +178,7 @@ module Gitlab
end
end
private
private
def
perform_count
(
model
,
estimate
)
def
perform_count
(
model
,
estimate
)
# If we estimate 0, we may not have statistics at all. Don't use them.
# If we estimate 0, we may not have statistics at all. Don't use them.
return
nil
unless
estimate
&&
estimate
>
0
return
nil
unless
estimate
&&
estimate
>
0
...
@@ -193,10 +195,10 @@ module Gitlab
...
@@ -193,10 +195,10 @@ module Gitlab
def
tablesample_count
(
model
,
estimate
)
def
tablesample_count
(
model
,
estimate
)
portion
=
(
TABLESAMPLE_ROW_TARGET
.
to_f
/
estimate
).
round
(
4
)
portion
=
(
TABLESAMPLE_ROW_TARGET
.
to_f
/
estimate
).
round
(
4
)
inverse
=
1
/
portion
inverse
=
1
/
portion
query
=
<<~
SQL
query
=
<<~
SQL
SELECT (COUNT(*)*
#{
inverse
}
)::integer AS count
SELECT (COUNT(*)*
#{
inverse
}
)::integer AS count
FROM
#{
model
.
table_name
}
TABLESAMPLE SYSTEM (
#{
portion
*
100
}
)
FROM
#{
model
.
table_name
}
TABLESAMPLE SYSTEM (
#{
portion
*
100
}
)
SQL
SQL
rows
=
ActiveRecord
::
Base
.
connection
.
select_all
(
query
)
rows
=
ActiveRecord
::
Base
.
connection
.
select_all
(
query
)
...
...
spec/lib/gitlab/database/count_spec.rb
View file @
9bb7c690
...
@@ -10,7 +10,7 @@ describe Gitlab::Database::Count do
...
@@ -10,7 +10,7 @@ describe Gitlab::Database::Count do
context
'.approximate_counts'
do
context
'.approximate_counts'
do
context
'selecting strategies'
do
context
'selecting strategies'
do
let
(
:strategies
)
{
[
double
(
's1'
,
:enabled?
=>
true
),
double
(
's2'
,
:enabled?
=>
false
)]
}
let
(
:strategies
)
{
[
double
(
's1'
,
enabled?:
true
),
double
(
's2'
,
enabled?:
false
)]
}
it
'uses only enabled strategies'
do
it
'uses only enabled strategies'
do
expect
(
strategies
[
0
]).
to
receive
(
:new
).
and_return
(
double
(
'strategy1'
,
count:
{}))
expect
(
strategies
[
0
]).
to
receive
(
:new
).
and_return
(
double
(
'strategy1'
,
count:
{}))
...
@@ -25,8 +25,8 @@ describe Gitlab::Database::Count do
...
@@ -25,8 +25,8 @@ describe Gitlab::Database::Count do
let
(
:strategies
)
do
let
(
:strategies
)
do
[
[
double
(
's1'
,
:enabled?
=>
true
,
new:
first_strategy
),
double
(
's1'
,
enabled?:
true
,
new:
first_strategy
),
double
(
's2'
,
:enabled?
=>
true
,
new:
second_strategy
)
double
(
's2'
,
enabled?:
true
,
new:
second_strategy
)
]
]
end
end
...
@@ -62,7 +62,7 @@ describe Gitlab::Database::Count do
...
@@ -62,7 +62,7 @@ describe Gitlab::Database::Count do
describe
'#count'
do
describe
'#count'
do
it
'counts all models'
do
it
'counts all models'
do
models
.
each
{
|
model
|
expect
(
model
).
to
receive
(
:count
).
and_call_original
}
expect
(
models
).
to
all
(
receive
(
:count
).
and_call_original
)
expect
(
subject
).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
expect
(
subject
).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
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