Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
09cdf425
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
09cdf425
编写于
12月 28, 2016
作者:
R
Rafael França
提交者:
GitHub
12月 28, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #27486 from schleyfox/optimize-journey-route-score-url_for
Optimize Journey::Route#score for url_for
上级
47cda2e1
f1525dac
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
15 addition
and
6 deletion
+15
-6
actionpack/lib/action_dispatch/journey/formatter.rb
actionpack/lib/action_dispatch/journey/formatter.rb
+5
-1
actionpack/lib/action_dispatch/journey/route.rb
actionpack/lib/action_dispatch/journey/route.rb
+9
-4
actionpack/test/journey/route_test.rb
actionpack/test/journey/route_test.rb
+1
-1
未找到文件。
actionpack/lib/action_dispatch/journey/formatter.rb
浏览文件 @
09cdf425
...
...
@@ -92,7 +92,11 @@ def match_route(name, options)
else
routes
=
non_recursive
(
cache
,
options
)
hash
=
routes
.
group_by
{
|
_
,
r
|
r
.
score
(
options
)
}
supplied_keys
=
options
.
each_with_object
({})
do
|
(
k
,
v
),
h
|
h
[
k
.
to_s
]
=
true
if
v
end
hash
=
routes
.
group_by
{
|
_
,
r
|
r
.
score
(
supplied_keys
)
}
hash
.
keys
.
sort
.
reverse_each
do
|
score
|
break
if
score
<
0
...
...
actionpack/lib/action_dispatch/journey/route.rb
浏览文件 @
09cdf425
...
...
@@ -96,13 +96,18 @@ def required_keys
required_parts
+
required_defaults
.
keys
end
def
score
(
constraint
s
)
def
score
(
supplied_key
s
)
required_keys
=
path
.
required_names
supplied_keys
=
constraints
.
map
{
|
k
,
v
|
v
&&
k
.
to_s
}.
compact
return
-
1
unless
(
required_keys
-
supplied_keys
).
empty?
required_keys
.
each
do
|
k
|
return
-
1
unless
supplied_keys
.
include?
(
k
)
end
score
=
0
path
.
names
.
each
do
|
k
|
score
+=
1
if
supplied_keys
.
include?
(
k
)
end
score
=
(
supplied_keys
&
path
.
names
).
length
score
+
(
required_defaults
.
length
*
2
)
end
...
...
actionpack/test/journey/route_test.rb
浏览文件 @
09cdf425
...
...
@@ -96,7 +96,7 @@ def test_score
path
=
Path
::
Pattern
.
from_string
"/:controller(/:action(/:id))(.:format)"
generic
=
Route
.
build
"name"
,
nil
,
path
,
constraints
,
[],
{}
knowledge
=
{
id:
20
,
controller:
"pages"
,
action:
"show"
}
knowledge
=
{
"id"
=>
true
,
"controller"
=>
true
,
"action"
=>
true
}
routes
=
[
specific
,
generic
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录