Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
15c68075
Commit
15c68075
authored
Aug 11, 2007
by
Dries
Browse files
- Patch
#154470
by pwolanin et al: optimize menu queries and indices.
parent
541c9673
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
includes/menu.inc
View file @
15c68075
This diff is collapsed.
Click to expand it.
modules/book/book.module
View file @
15c68075
...
...
@@ -620,7 +620,7 @@ function book_outline_form_submit($form, &$form_state) {
}
}
else
{
drupal_set_message
(
t
(
'There was an error adding the post to the book.'
));
drupal_set_message
(
t
(
'There was an error adding the post to the book.'
)
,
'error'
);
}
}
...
...
@@ -1451,8 +1451,9 @@ function book_menu_subtree_data($item) {
$data
=
$cache
->
data
;
}
else
{
$match
=
array
(
"menu_name = '%s'"
);
$args
=
array
(
$item
[
'menu_name'
]);
$i
=
1
;
$match
=
array
();
while
(
$i
<=
MENU_MAX_DEPTH
&&
$item
[
"p
$i
"
])
{
$match
[]
=
"p
$i
= %d"
;
$args
[]
=
$item
[
"p
$i
"
];
...
...
@@ -1460,10 +1461,10 @@ function book_menu_subtree_data($item) {
}
$sql
=
"
SELECT b.*, m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, ml.*
FROM
{
menu_links
}
ml
LEFT
JOIN
{
menu_router
}
m ON m.path = ml.router_path
FROM
{
menu_links
}
ml
INNER
JOIN
{
menu_router
}
m ON m.path = ml.router_path
INNER JOIN
{
book
}
b ON ml.mlid = b.mlid
WHERE
ml.hidden >= 0 AND
"
.
implode
(
' AND '
,
$match
)
.
"
ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC"
;
WHERE "
.
implode
(
' AND '
,
$match
)
.
"
ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5
ASC, p6 ASC, p7 ASC, p8 ASC, p9
ASC"
;
$data
[
'tree'
]
=
menu_tree_data
(
db_query
(
$sql
,
$args
),
array
(),
$item
[
'depth'
]);
$data
[
'node_links'
]
=
array
();
...
...
modules/menu/menu.module
View file @
15c68075
...
...
@@ -70,6 +70,8 @@ function menu_menu() {
'title'
=>
'Customize menu'
,
'page callback'
=>
'menu_overview'
,
'page arguments'
=>
array
(
3
),
'title callback'
=>
'menu_overview_title'
,
'title arguments'
=>
array
(
3
),
'access arguments'
=>
array
(
'administer menu'
),
'type'
=>
MENU_CALLBACK
);
$items
[
'admin/build/menu-customize/%menu/list'
]
=
array
(
...
...
@@ -141,6 +143,13 @@ function menu_enable() {
menu_cache_clear_all
();
}
/**
* Title callback for the menu overview page and links.
*/
function
menu_overview_title
(
$menu
)
{
return
t
(
'!menu_title (overview)'
,
array
(
'!menu_title'
=>
$menu
[
'title'
]));
}
/**
* Load the data for a single custom menu.
*/
...
...
@@ -171,14 +180,14 @@ function menu_overview($menu) {
$sql
=
"
SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, ml.*
FROM
{
menu_links
}
ml LEFT JOIN
{
menu_router
}
m ON m.path = ml.router_path
WHERE ml.menu_name = '%s'
AND ml.hidden >= 0
ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC"
;
$sql_count
=
"SELECT COUNT(*) FROM
{
menu_links
}
ml WHERE menu_name = '%s'
AND hidden >= 0
"
;
WHERE ml.menu_name = '%s'
ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5
ASC, p6 ASC, p7 ASC, p8 ASC, p9
ASC"
;
$sql_count
=
"SELECT COUNT(*) FROM
{
menu_links
}
ml WHERE menu_name = '%s'"
;
$result
=
pager_query
(
$sql
,
200
,
0
,
$sql_count
,
$menu
[
'menu_name'
]);
$tree
=
menu_tree_data
(
$result
);
$node_links
=
array
();
menu_tree_collect_node_links
(
$tree
,
$node_links
);
menu_tree_check_access
(
$tree
,
$node_links
,
TRUE
);
menu_tree_check_access
(
$tree
,
$node_links
);
$rows
=
_menu_overview_tree
(
$tree
);
$output
=
theme
(
'table'
,
$header
,
$rows
);
$output
.
=
theme
(
'pager'
,
NULL
,
200
,
0
);
...
...
@@ -192,9 +201,11 @@ function _menu_overview_tree($tree) {
static
$rows
=
array
();
foreach
(
$tree
as
$data
)
{
$title
=
''
;
if
(
$item
=
$data
[
'link'
])
{
$item
=
$data
[
'link'
];
// Don't show callbacks; these have $item['hidden'] < 0.
if
(
$item
&&
$item
[
'hidden'
]
>=
0
)
{
$title
=
str_repeat
(
' '
,
$item
[
'depth'
]
-
1
)
.
(
$item
[
'depth'
]
>
1
?
'- '
:
''
);
$title
.
=
l
(
$item
[
'
link_
title'
],
$item
[
'href'
],
$item
[
'options'
]);
$title
.
=
l
(
$item
[
'title'
],
$item
[
'href'
],
$item
[
'options'
]);
// Populate the operations field.
$operations
=
array
();
// Set the edit column.
...
...
@@ -360,7 +371,9 @@ function menu_item_delete_submit($form, &$form_state) {
function
menu_edit_item_submit
(
$form
,
&
$form_state
)
{
$form_state
[
'values'
][
'options'
][
'attributes'
][
'title'
]
=
$form_state
[
'values'
][
'description'
];
list
(
$form_state
[
'values'
][
'menu_name'
],
$form_state
[
'values'
][
'plid'
])
=
explode
(
':'
,
$form_state
[
'values'
][
'parent'
]);
menu_link_save
(
$form_state
[
'values'
]);
if
(
!
menu_link_save
(
$form_state
[
'values'
]))
{
drupal_set_message
(
t
(
'There was an error saving the menu link.'
),
'error'
);
}
$form_state
[
'redirect'
]
=
'admin/build/menu-customize/'
.
$form_state
[
'values'
][
'menu_name'
];
}
...
...
@@ -379,7 +392,7 @@ function menu_edit_item_submit($form, &$form_state) {
function
menu_parent_options
(
$menus
,
$item
)
{
foreach
(
$menus
as
$menu_name
=>
$title
)
{
$tree
=
menu_tree_all_data
(
$menu_name
,
NULL
,
TRUE
);
$tree
=
menu_tree_all_data
(
$menu_name
,
NULL
);
$options
[
$menu_name
.
':0'
]
=
'<'
.
$title
.
'>'
;
_menu_parents_recurse
(
$tree
,
$menu_name
,
'--'
,
$options
,
$item
[
'mlid'
]);
}
...
...
@@ -391,14 +404,14 @@ function menu_parent_options($menus, $item) {
*/
function
_menu_parents_recurse
(
$tree
,
$menu_name
,
$indent
,
&
$options
,
$exclude
)
{
foreach
(
$tree
as
$data
)
{
if
(
$data
[
'link'
][
'mlid'
]
!=
$exclude
)
{
if
(
$data
[
'link'
][
'mlid'
]
!=
$exclude
&&
$data
[
'link'
][
'hidden'
]
>=
0
)
{
$title
=
$indent
.
' '
.
truncate_utf8
(
$data
[
'link'
][
'title'
],
30
,
TRUE
,
FALSE
);
if
(
$data
[
'link'
][
'hidden'
])
{
$title
.
=
' ('
.
t
(
'disabled'
)
.
')'
;
}
$options
[
$menu_name
.
':'
.
$data
[
'link'
][
'mlid'
]]
=
$title
;
if
(
$data
[
'below'
]
&&
$data
[
'link'
][
'depth'
]
<
MENU_MAX_DEPTH
-
1
)
{
_menu_parents_recurse
(
$data
[
'below'
],
$menu_name
,
$indent
.
'--'
,
$options
,
$exclude
);
_menu_parents_recurse
(
$data
[
'below'
],
$menu_name
,
$indent
.
'--'
,
$options
,
$exclude
);
}
}
}
...
...
@@ -500,7 +513,7 @@ function menu_delete_menu_confirm_submit($form, &$form_state) {
// Delete all links to the overview page for this menu.
$result
=
db_query
(
"SELECT mlid FROM
{
menu_links
}
ml WHERE ml.link_path = '%s'"
,
'admin/build/menu-customize/'
.
$menu
[
'menu_name'
]);
while
(
$m
=
db_fetch_array
(
$result
))
{
menu_link_delete
(
$m
[
'mlid'
]);
menu_link_delete
(
$m
[
'mlid'
]);
}
// Delete all the links in the menu and the menu from the list of custom menus.
db_query
(
"DELETE FROM
{
menu_links
}
WHERE menu_name = '%s'"
,
$menu
[
'menu_name'
]);
...
...
@@ -527,7 +540,7 @@ function menu_edit_menu_validate($form, &$form_state) {
// We will add 'menu-' to the menu name to help avoid name-space conflicts.
$item
[
'menu_name'
]
=
'menu-'
.
$item
[
'menu_name'
];
if
(
db_result
(
db_query
(
"SELECT menu_name FROM
{
menu_custom
}
WHERE menu_name = '%s'"
,
$item
[
'menu_name'
]))
||
db_result
(
db_query_range
(
"SELECT menu_name FROM
{
menu_links
}
WHERE menu_name = '%s'"
,
$item
[
'menu_name'
],
0
,
1
)))
{
db_result
(
db_query_range
(
"SELECT menu_name FROM
{
menu_links
}
WHERE menu_name = '%s'"
,
$item
[
'menu_name'
],
0
,
1
)))
{
form_set_error
(
'menu_name'
,
t
(
'Menu already exists'
));
}
}
...
...
@@ -663,7 +676,9 @@ function menu_nodeapi(&$node, $op) {
if
(
!
$item
[
'customized'
])
{
$item
[
'options'
][
'attributes'
][
'title'
]
=
trim
(
$node
->
title
);
}
menu_link_save
(
$item
);
if
(
!
menu_link_save
(
$item
))
{
drupal_set_message
(
t
(
'There was an error saving the menu link.'
),
'error'
);
}
}
}
break
;
...
...
modules/system/system.install
View file @
15c68075
...
...
@@ -3333,6 +3333,9 @@ function system_update_6020() {
'plid'
=>
array
(
'type'
=>
'int'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
'link_path'
=>
array
(
'type'
=>
'varchar'
,
'length'
=>
255
,
'not null'
=>
TRUE
,
'default'
=>
''
),
'router_path'
=>
array
(
'type'
=>
'varchar'
,
'length'
=>
255
,
'not null'
=>
TRUE
,
'default'
=>
''
),
'link_title'
=>
array
(
'type'
=>
'varchar'
,
'length'
=>
255
,
'not null'
=>
TRUE
,
'default'
=>
''
),
'options'
=>
array
(
'type'
=>
'text'
,
'not null'
=>
FALSE
),
'module'
=>
array
(
'type'
=>
'varchar'
,
'length'
=>
255
,
'not null'
=>
TRUE
,
'default'
=>
'system'
),
'hidden'
=>
array
(
'type'
=>
'int'
,
'not null'
=>
TRUE
,
'default'
=>
0
,
'size'
=>
'small'
),
'external'
=>
array
(
'type'
=>
'int'
,
'not null'
=>
TRUE
,
'default'
=>
0
,
'size'
=>
'small'
),
'has_children'
=>
array
(
'type'
=>
'int'
,
'not null'
=>
TRUE
,
'default'
=>
0
,
'size'
=>
'small'
),
...
...
@@ -3346,16 +3349,15 @@ function system_update_6020() {
'p4'
=>
array
(
'type'
=>
'int'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
'p5'
=>
array
(
'type'
=>
'int'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
'p6'
=>
array
(
'type'
=>
'int'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
'
module'
=>
array
(
'type'
=>
'
varchar'
,
'length
'
=>
255
,
'not null'
=>
TRUE
,
'default'
=>
'system'
),
'
link_title'
=>
array
(
'type'
=>
'
varchar'
,
'length
'
=>
255
,
'not null'
=>
TRUE
,
'default'
=>
''
),
'
options'
=>
array
(
'type'
=>
'
text'
,
'not null'
=>
FALSE
)
'
p7'
=>
array
(
'type'
=>
'
int'
,
'unsigned
'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
'
p8'
=>
array
(
'type'
=>
'
int'
,
'unsigned
'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
'
p9'
=>
array
(
'type'
=>
'
int'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
),
'indexes'
=>
array
(
'expanded_children'
=>
array
(
'expanded'
,
'has_children'
),
'menu_name_path'
=>
array
(
'menu_name'
,
'link_path'
),
'plid'
=>
array
(
'plid'
),
'parents'
=>
array
(
'p1'
,
'p2'
,
'p3'
,
'p4'
,
'p5'
),
'router_path'
=>
array
(
'router_path'
),
'path_menu'
=>
array
(
array
(
'link_path'
,
128
),
'menu_name'
),
'menu_plid_expand_child'
=>
array
(
'menu_name'
,
'plid'
,
'expanded'
,
'has_children'
),
'menu_parents'
=>
array
(
'menu_name'
,
'p1'
,
'p2'
,
'p3'
,
'p4'
,
'p5'
,
'p6'
,
'p7'
,
'p8'
,
'p9'
),
'router_path'
=>
array
(
array
(
'router_path'
,
128
)),
),
'primary key'
=>
array
(
'mlid'
),
);
...
...
modules/system/system.schema
View file @
15c68075
...
...
@@ -104,6 +104,9 @@ function system_schema() {
'plid'
=>
array
(
'type'
=>
'int'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
'link_path'
=>
array
(
'type'
=>
'varchar'
,
'length'
=>
255
,
'not null'
=>
TRUE
,
'default'
=>
''
),
'router_path'
=>
array
(
'type'
=>
'varchar'
,
'length'
=>
255
,
'not null'
=>
TRUE
,
'default'
=>
''
),
'link_title'
=>
array
(
'type'
=>
'varchar'
,
'length'
=>
255
,
'not null'
=>
TRUE
,
'default'
=>
''
),
'options'
=>
array
(
'type'
=>
'text'
,
'not null'
=>
FALSE
),
'module'
=>
array
(
'type'
=>
'varchar'
,
'length'
=>
255
,
'not null'
=>
TRUE
,
'default'
=>
'system'
),
'hidden'
=>
array
(
'type'
=>
'int'
,
'not null'
=>
TRUE
,
'default'
=>
0
,
'size'
=>
'small'
),
'external'
=>
array
(
'type'
=>
'int'
,
'not null'
=>
TRUE
,
'default'
=>
0
,
'size'
=>
'small'
),
'has_children'
=>
array
(
'type'
=>
'int'
,
'not null'
=>
TRUE
,
'default'
=>
0
,
'size'
=>
'small'
),
...
...
@@ -117,16 +120,15 @@ function system_schema() {
'p4'
=>
array
(
'type'
=>
'int'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
'p5'
=>
array
(
'type'
=>
'int'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
'p6'
=>
array
(
'type'
=>
'int'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
'
module'
=>
array
(
'type'
=>
'
varchar'
,
'length
'
=>
255
,
'not null'
=>
TRUE
,
'default'
=>
'system'
),
'
link_title'
=>
array
(
'type'
=>
'
varchar'
,
'length
'
=>
255
,
'not null'
=>
TRUE
,
'default'
=>
''
),
'
options'
=>
array
(
'type'
=>
'
text'
,
'not null'
=>
FALSE
)
'
p7'
=>
array
(
'type'
=>
'
int'
,
'unsigned
'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
'
p8'
=>
array
(
'type'
=>
'
int'
,
'unsigned
'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
'
p9'
=>
array
(
'type'
=>
'
int'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
),
),
'indexes'
=>
array
(
'expanded_children'
=>
array
(
'expanded'
,
'has_children'
),
'menu_name_path'
=>
array
(
'menu_name'
,
'link_path'
),
'plid'
=>
array
(
'plid'
),
'parents'
=>
array
(
'p1'
,
'p2'
,
'p3'
,
'p4'
,
'p5'
),
'router_path'
=>
array
(
'router_path'
),
'path_menu'
=>
array
(
array
(
'link_path'
,
128
),
'menu_name'
),
'menu_plid_expand_child'
=>
array
(
'menu_name'
,
'plid'
,
'expanded'
,
'has_children'
),
'menu_parents'
=>
array
(
'menu_name'
,
'p1'
,
'p2'
,
'p3'
,
'p4'
,
'p5'
,
'p6'
,
'p7'
,
'p8'
,
'p9'
),
'router_path'
=>
array
(
array
(
'router_path'
,
128
)),
),
'primary key'
=>
array
(
'mlid'
),
);
...
...
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