Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
259493bb
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
259493bb
编写于
7月 24, 2019
作者:
A
Andreas Brandl
提交者:
Nick Thomas
7月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable tablesample count strategy by default
https://gitlab.com/gitlab-org/gitlab-ce/issues/58792
上级
25698fda
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
12 addition
and
78 deletion
+12
-78
changelogs/unreleased/ab-count-strategies.yml
changelogs/unreleased/ab-count-strategies.yml
+5
-0
lib/gitlab/database/count.rb
lib/gitlab/database/count.rb
+5
-7
lib/gitlab/database/count/exact_count_strategy.rb
lib/gitlab/database/count/exact_count_strategy.rb
+0
-4
lib/gitlab/database/count/reltuples_count_strategy.rb
lib/gitlab/database/count/reltuples_count_strategy.rb
+0
-4
lib/gitlab/database/count/tablesample_count_strategy.rb
lib/gitlab/database/count/tablesample_count_strategy.rb
+0
-4
spec/lib/gitlab/database/count/exact_count_strategy_spec.rb
spec/lib/gitlab/database/count/exact_count_strategy_spec.rb
+0
-14
spec/lib/gitlab/database/count/reltuples_count_strategy_spec.rb
...ib/gitlab/database/count/reltuples_count_strategy_spec.rb
+0
-14
spec/lib/gitlab/database/count/tablesample_count_strategy_spec.rb
.../gitlab/database/count/tablesample_count_strategy_spec.rb
+0
-18
spec/lib/gitlab/database/count_spec.rb
spec/lib/gitlab/database/count_spec.rb
+2
-13
未找到文件。
changelogs/unreleased/ab-count-strategies.yml
0 → 100644
浏览文件 @
259493bb
---
title
:
Use tablesample approximate counting by default.
merge_request
:
31048
author
:
type
:
performance
lib/gitlab/database/count.rb
浏览文件 @
259493bb
...
...
@@ -37,16 +37,14 @@ module Gitlab
# @return [Hash] of Model -> count mapping
def
self
.
approximate_counts
(
models
,
strategies:
[
TablesampleCountStrategy
,
ReltuplesCountStrategy
,
ExactCountStrategy
])
strategies
.
each_with_object
({})
do
|
strategy
,
counts_by_model
|
if
strategy
.
enabled?
models_with_missing_counts
=
models
-
counts_by_model
.
keys
models_with_missing_counts
=
models
-
counts_by_model
.
keys
break
counts_by_model
if
models_with_missing_counts
.
empty?
break
counts_by_model
if
models_with_missing_counts
.
empty?
counts
=
strategy
.
new
(
models_with_missing_counts
).
count
counts
=
strategy
.
new
(
models_with_missing_counts
).
count
counts
.
each
do
|
model
,
count
|
counts_by_model
[
model
]
=
count
end
counts
.
each
do
|
model
,
count
|
counts_by_model
[
model
]
=
count
end
end
end
...
...
lib/gitlab/database/count/exact_count_strategy.rb
浏览文件 @
259493bb
...
...
@@ -23,10 +23,6 @@ module Gitlab
rescue
*
CONNECTION_ERRORS
{}
end
def
self
.
enabled?
true
end
end
end
end
...
...
lib/gitlab/database/count/reltuples_count_strategy.rb
浏览文件 @
259493bb
...
...
@@ -31,10 +31,6 @@ module Gitlab
{}
end
def
self
.
enabled?
Gitlab
::
Database
.
postgresql?
end
private
# Models using single-type inheritance (STI) don't work with
...
...
lib/gitlab/database/count/tablesample_count_strategy.rb
浏览文件 @
259493bb
...
...
@@ -28,10 +28,6 @@ module Gitlab
{}
end
def
self
.
enabled?
Gitlab
::
Database
.
postgresql?
&&
Feature
.
enabled?
(
:tablesample_counts
)
end
private
def
perform_count
(
model
,
estimate
)
...
...
spec/lib/gitlab/database/count/exact_count_strategy_spec.rb
浏览文件 @
259493bb
...
...
@@ -23,18 +23,4 @@ describe Gitlab::Database::Count::ExactCountStrategy do
expect
(
subject
).
to
eq
({})
end
end
describe
'.enabled?'
do
it
'is enabled for PostgreSQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
expect
(
described_class
.
enabled?
).
to
be_truthy
end
it
'is enabled for MySQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
described_class
.
enabled?
).
to
be_truthy
end
end
end
spec/lib/gitlab/database/count/reltuples_count_strategy_spec.rb
浏览文件 @
259493bb
...
...
@@ -48,18 +48,4 @@ describe Gitlab::Database::Count::ReltuplesCountStrategy do
end
end
end
describe
'.enabled?'
do
it
'is enabled for PostgreSQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
expect
(
described_class
.
enabled?
).
to
be_truthy
end
it
'is disabled for MySQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
described_class
.
enabled?
).
to
be_falsey
end
end
end
spec/lib/gitlab/database/count/tablesample_count_strategy_spec.rb
浏览文件 @
259493bb
...
...
@@ -56,22 +56,4 @@ describe Gitlab::Database::Count::TablesampleCountStrategy do
end
end
end
describe
'.enabled?'
do
before
do
stub_feature_flags
(
tablesample_counts:
true
)
end
it
'is enabled for PostgreSQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
expect
(
described_class
.
enabled?
).
to
be_truthy
end
it
'is disabled for MySQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
described_class
.
enabled?
).
to
be_falsey
end
end
end
spec/lib/gitlab/database/count_spec.rb
浏览文件 @
259493bb
...
...
@@ -9,24 +9,13 @@ describe Gitlab::Database::Count do
let
(
:models
)
{
[
Project
,
Identity
]
}
context
'.approximate_counts'
do
context
'selecting strategies'
do
let
(
:strategies
)
{
[
double
(
's1'
,
enabled?:
true
),
double
(
's2'
,
enabled?:
false
)]
}
it
'uses only enabled strategies'
do
expect
(
strategies
[
0
]).
to
receive
(
:new
).
and_return
(
double
(
'strategy1'
,
count:
{}))
expect
(
strategies
[
1
]).
not_to
receive
(
:new
)
described_class
.
approximate_counts
(
models
,
strategies:
strategies
)
end
end
context
'fallbacks'
do
subject
{
described_class
.
approximate_counts
(
models
,
strategies:
strategies
)
}
let
(
:strategies
)
do
[
double
(
's1'
,
enabled?:
true
,
new:
first_strategy
),
double
(
's2'
,
enabled?:
true
,
new:
second_strategy
)
double
(
's1'
,
new:
first_strategy
),
double
(
's2'
,
new:
second_strategy
)
]
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录