Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
db271a6b
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,发现更多精彩内容 >>
提交
db271a6b
编写于
8月 03, 2017
作者:
S
Sean McGivern
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'tc-no-todo-service-select-mysql' into 'master'
Avoid plucking Todo ids in TodoService - take 2 See merge request !11415
上级
00a02d14
a488fc0a
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
62 addition
and
22 deletion
+62
-22
app/controllers/dashboard/todos_controller.rb
app/controllers/dashboard/todos_controller.rb
+2
-2
app/finders/todos_finder.rb
app/finders/todos_finder.rb
+11
-2
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+1
-1
app/services/todo_service.rb
app/services/todo_service.rb
+10
-6
changelogs/unreleased/tc-no-todo-service-select.yml
changelogs/unreleased/tc-no-todo-service-select.yml
+4
-0
lib/api/todos.rb
lib/api/todos.rb
+3
-3
lib/api/v3/todos.rb
lib/api/v3/todos.rb
+3
-3
spec/services/todo_service_spec.rb
spec/services/todo_service_spec.rb
+28
-5
未找到文件。
app/controllers/dashboard/todos_controller.rb
浏览文件 @
db271a6b
...
...
@@ -13,7 +13,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end
def
destroy
TodoService
.
new
.
mark_todos_as_done_by_ids
(
[
params
[
:id
]
],
current_user
)
TodoService
.
new
.
mark_todos_as_done_by_ids
(
params
[
:id
],
current_user
)
respond_to
do
|
format
|
format
.
html
do
...
...
@@ -37,7 +37,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end
def
restore
TodoService
.
new
.
mark_todos_as_pending_by_ids
(
[
params
[
:id
]
],
current_user
)
TodoService
.
new
.
mark_todos_as_pending_by_ids
(
params
[
:id
],
current_user
)
render
json:
todos_counts
end
...
...
app/finders/todos_finder.rb
浏览文件 @
db271a6b
...
...
@@ -95,9 +95,18 @@ class TodosFinder
@project
end
def
project_ids
(
items
)
ids
=
items
.
except
(
:order
).
select
(
:project_id
)
if
Gitlab
::
Database
.
mysql?
# To make UPDATE work on MySQL, wrap it in a SELECT with an alias
ids
=
Todo
.
except
(
:order
).
select
(
'*'
).
from
(
"(
#{
ids
.
to_sql
}
) AS t"
)
end
ids
end
def
projects
(
items
)
item_project_ids
=
items
.
reorder
(
nil
).
select
(
:project_id
)
ProjectsFinder
.
new
(
current_user:
current_user
,
project_ids_relation:
item_project_ids
).
execute
ProjectsFinder
.
new
(
current_user:
current_user
,
project_ids_relation:
project_ids
(
items
)).
execute
end
def
type?
...
...
app/services/issuable_base_service.rb
浏览文件 @
db271a6b
...
...
@@ -288,7 +288,7 @@ class IssuableBaseService < BaseService
todo_service
.
mark_todo
(
issuable
,
current_user
)
when
'done'
todo
=
TodosFinder
.
new
(
current_user
).
execute
.
find_by
(
target:
issuable
)
todo_service
.
mark_todos_as_done
([
todo
]
,
current_user
)
if
todo
todo_service
.
mark_todos_as_done
_by_ids
(
todo
,
current_user
)
if
todo
end
end
...
...
app/services/todo_service.rb
浏览文件 @
db271a6b
...
...
@@ -170,20 +170,22 @@ class TodoService
# When user marks some todos as done
def
mark_todos_as_done
(
todos
,
current_user
)
update_todos_state
_by_ids
(
todos
.
select
(
&
:id
)
,
current_user
,
:done
)
update_todos_state
(
todos
,
current_user
,
:done
)
end
def
mark_todos_as_done_by_ids
(
ids
,
current_user
)
update_todos_state_by_ids
(
ids
,
current_user
,
:done
)
todos
=
todos_by_ids
(
ids
,
current_user
)
mark_todos_as_done
(
todos
,
current_user
)
end
# When user marks some todos as pending
def
mark_todos_as_pending
(
todos
,
current_user
)
update_todos_state
_by_ids
(
todos
.
select
(
&
:id
)
,
current_user
,
:pending
)
update_todos_state
(
todos
,
current_user
,
:pending
)
end
def
mark_todos_as_pending_by_ids
(
ids
,
current_user
)
update_todos_state_by_ids
(
ids
,
current_user
,
:pending
)
todos
=
todos_by_ids
(
ids
,
current_user
)
mark_todos_as_pending
(
todos
,
current_user
)
end
# When user marks an issue as todo
...
...
@@ -198,9 +200,11 @@ class TodoService
private
def
update_todos_state_by_ids
(
ids
,
current_user
,
state
)
todos
=
current_user
.
todos
.
where
(
id:
ids
)
def
todos_by_ids
(
ids
,
current_user
)
current_user
.
todos
.
where
(
id:
Array
(
ids
))
end
def
update_todos_state
(
todos
,
current_user
,
state
)
# Only update those that are not really on that state
todos
=
todos
.
where
.
not
(
state:
state
)
todos_ids
=
todos
.
pluck
(
:id
)
...
...
changelogs/unreleased/tc-no-todo-service-select.yml
0 → 100644
浏览文件 @
db271a6b
---
title
:
Avoid plucking Todo ids in TodoService
merge_request
:
10845
author
:
lib/api/todos.rb
浏览文件 @
db271a6b
...
...
@@ -59,10 +59,10 @@ module API
requires
:id
,
type:
Integer
,
desc:
'The ID of the todo being marked as done'
end
post
':id/mark_as_done'
do
todo
=
current_user
.
todos
.
find
(
params
[
:id
]
)
TodoService
.
new
.
mark_todos_as_done
([
todo
],
current_user
)
TodoService
.
new
.
mark_todos_as_done_by_ids
(
params
[
:id
],
current_user
)
todo
=
Todo
.
find
(
params
[
:id
]
)
present
todo
.
reload
,
with:
Entities
::
Todo
,
current_user:
current_user
present
todo
,
with:
Entities
::
Todo
,
current_user:
current_user
end
desc
'Mark all todos as done'
...
...
lib/api/v3/todos.rb
浏览文件 @
db271a6b
...
...
@@ -11,10 +11,10 @@ module API
requires
:id
,
type:
Integer
,
desc:
'The ID of the todo being marked as done'
end
delete
':id'
do
todo
=
current_user
.
todos
.
find
(
params
[
:id
]
)
TodoService
.
new
.
mark_todos_as_done
([
todo
],
current_user
)
TodoService
.
new
.
mark_todos_as_done_by_ids
(
params
[
:id
],
current_user
)
todo
=
Todo
.
find
(
params
[
:id
]
)
present
todo
.
reload
,
with:
::
API
::
Entities
::
Todo
,
current_user:
current_user
present
todo
,
with:
::
API
::
Entities
::
Todo
,
current_user:
current_user
end
desc
'Mark all todos as done'
...
...
spec/services/todo_service_spec.rb
浏览文件 @
db271a6b
...
...
@@ -336,7 +336,7 @@ describe TodoService do
describe
'#mark_todos_as_done'
do
it_behaves_like
'updating todos state'
,
:mark_todos_as_done
,
:pending
,
:done
do
let
(
:collection
)
{
[
first_todo
,
second_todo
]
}
let
(
:collection
)
{
Todo
.
all
}
end
end
...
...
@@ -348,7 +348,7 @@ describe TodoService do
describe
'#mark_todos_as_pending'
do
it_behaves_like
'updating todos state'
,
:mark_todos_as_pending
,
:done
,
:pending
do
let
(
:collection
)
{
[
first_todo
,
second_todo
]
}
let
(
:collection
)
{
Todo
.
all
}
end
end
...
...
@@ -880,14 +880,16 @@ describe TodoService do
it
'marks an array of todos as done'
do
todo
=
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
expect
{
described_class
.
new
.
mark_todos_as_done
([
todo
],
john_doe
)
}
todos
=
TodosFinder
.
new
(
john_doe
,
{}).
execute
expect
{
described_class
.
new
.
mark_todos_as_done
(
todos
,
john_doe
)
}
.
to
change
{
todo
.
reload
.
state
}.
from
(
'pending'
).
to
(
'done'
)
end
it
'returns the ids of updated todos'
do
# Needed on API
todo
=
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
expect
(
described_class
.
new
.
mark_todos_as_done
([
todo
],
john_doe
)).
to
eq
([
todo
.
id
])
todos
=
TodosFinder
.
new
(
john_doe
,
{}).
execute
expect
(
described_class
.
new
.
mark_todos_as_done
(
todos
,
john_doe
)).
to
eq
([
todo
.
id
])
end
context
'when some of the todos are done already'
do
...
...
@@ -907,11 +909,32 @@ describe TodoService do
expect
(
described_class
.
new
.
mark_todos_as_done
(
Todo
.
all
,
john_doe
)).
to
eq
([])
end
end
end
describe
'#mark_todos_as_done_by_ids'
do
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
author:
author
,
assignees:
[
john_doe
])
}
let
(
:another_issue
)
{
create
(
:issue
,
project:
project
,
author:
author
,
assignees:
[
john_doe
])
}
it
'marks an array of todo ids as done'
do
todo
=
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
another_todo
=
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
another_issue
,
project:
project
)
expect
{
described_class
.
new
.
mark_todos_as_done_by_ids
([
todo
.
id
,
another_todo
.
id
],
john_doe
)
}
.
to
change
{
john_doe
.
todos
.
done
.
count
}.
from
(
0
).
to
(
2
)
end
it
'marks a single todo id as done'
do
todo
=
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
expect
{
described_class
.
new
.
mark_todos_as_done_by_ids
(
todo
.
id
,
john_doe
)
}
.
to
change
{
todo
.
reload
.
state
}.
from
(
'pending'
).
to
(
'done'
)
end
it
'caches the number of todos of a user'
,
:use_clean_rails_memory_store_caching
do
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
todo
=
create
(
:todo
,
:mentioned
,
user:
john_doe
,
target:
issue
,
project:
project
)
described_class
.
new
.
mark_todos_as_done
([
todo
],
john_doe
)
described_class
.
new
.
mark_todos_as_done_by_ids
(
todo
,
john_doe
)
expect_any_instance_of
(
TodosFinder
).
not_to
receive
(
:execute
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录