Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
abd2477d
Commit
abd2477d
authored
Nov 26, 2007
by
Gábor Hojtsy
Browse files
Options
Downloads
Patches
Plain Diff
#170514
by pwolanin: drastically reduce calls to cache clearing when the menu needs to be rebuilt
parent
1a5f3010
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
includes/menu.inc
+47
-16
47 additions, 16 deletions
includes/menu.inc
with
47 additions
and
16 deletions
includes/menu.inc
+
47
−
16
View file @
abd2477d
...
...
@@ -1472,7 +1472,16 @@ function menu_link_load($mlid) {
* Clears the cached cached data for a single named menu.
*/
function
menu_cache_clear
(
$menu_name
=
'navigation'
)
{
static
$cache_cleared
=
array
();
if
(
empty
(
$cache_cleared
[
$menu_name
]))
{
cache_clear_all
(
'links:'
.
$menu_name
.
':'
,
'cache_menu'
,
TRUE
);
$cache_cleared
[
$menu_name
]
=
1
;
}
elseif
(
$cache_cleared
[
$menu_name
]
==
1
)
{
register_shutdown_function
(
'cache_clear_all'
,
'links:'
.
$menu_name
.
':'
,
'cache_menu'
,
TRUE
);
$cache_cleared
[
$menu_name
]
=
2
;
}
}
/**
...
...
@@ -1492,7 +1501,7 @@ function menu_rebuild() {
$menu
=
menu_router_build
(
TRUE
);
_menu_navigation_links_rebuild
(
$menu
);
// Clear the page and block caches.
cache
_clear_
all
();
_menu
_clear_
page_cache
();
}
/**
...
...
@@ -1613,9 +1622,9 @@ function menu_link_delete($mlid, $path = NULL) {
/**
* Helper function for menu_link_delete; deletes a single menu link.
*/
function
_menu_delete_item
(
$item
,
$rebuild
=
FALSE
)
{
// System-created items are
only
deleted
on menu rebuild
.
if
(
$item
&&
(
$item
[
'module'
]
!=
'system'
||
$rebuild
))
{
function
_menu_delete_item
(
$item
)
{
// System-created items are
never
deleted.
if
(
$item
&&
(
$item
[
'module'
]
!=
'system'
))
{
// Children get re-attached to the item's parent.
if
(
$item
[
'has_children'
])
{
...
...
@@ -1630,13 +1639,8 @@ function _menu_delete_item($item, $rebuild = FALSE) {
// Update the has_children status of the parent.
_menu_update_parental_status
(
$item
);
// If we are rebuilding the menu, the menu cache has already been cleared.
if
(
!
$rebuild
)
{
menu_cache_clear
(
$item
[
'menu_name'
]);
// Clear the page and block caches.
cache_clear_all
();
}
_menu_clear_page_cache
();
}
}
...
...
@@ -1773,16 +1777,43 @@ function menu_link_save(&$item) {
if
(
$existing_item
&&
$menu_name
!=
$existing_item
[
'menu_name'
])
{
menu_cache_clear
(
$existing_item
[
'menu_name'
]);
}
_menu_clear_page_cache
();
return
$item
[
'mlid'
];
}
/**
* Helper function to clear the page and block caches at most twice per page load.
*/
function
_menu_clear_page_cache
()
{
static
$cache_cleared
=
0
;
// Clear the page and block caches, but at most twice, including at
// the end of the page load when there are multple links saved or deleted.
if
(
empty
(
$cache_cleared
))
{
cache_clear_all
();
// Keep track of which menus have expanded items.
_menu_set_expanded_menus
();
$cache_cleared
=
1
;
}
elseif
(
$cache_cleared
==
1
)
{
register_shutdown_function
(
'cache_clear_all'
);
// Keep track of which menus have expanded items.
register_shutdown_function
(
'_menu_set_expanded_menus'
);
$cache_cleared
=
2
;
}
}
/**
* Helper function to update a list of menus with expanded items
*/
function
_menu_set_expanded_menus
()
{
$names
=
array
();
$result
=
db_query
(
"SELECT menu_name FROM
{
menu_links
}
WHERE expanded != 0 GROUP BY menu_name"
);
while
(
$n
=
db_fetch_array
(
$result
))
{
$names
[]
=
$n
[
'menu_name'
];
}
variable_set
(
'menu_expanded'
,
$names
);
// Clear the page and block caches.
cache_clear_all
();
return
$item
[
'mlid'
];
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment