node_type_save() calls content_type_create() which correctly notes that:

 * node_get_types() is still missing the new type at this point, so no
 * use to call content_clear_type_cache() or menu_rebuild() here. Instead
 * we set a flag to make sure it gets rebuilt on next page load.

node_get_types() keeps a static cache of node types which is not reset by node_type_save(). This is certainly a bug in node.module. chx and I are working on a general static caching solution, but it isn't in yet.

However, there is still a CCK bug. Since clearing the CCK cache is currently useless at that point, content_type_create() stores a boolean in $_SESSION to indicate that the cache should be cleared on the next page load. That's fine unless node_type_save() is not called from a page request but from a normal program. Then there is no subsequent load for the $_SESSION and the cache is never cleared.

You could set a variable instead of setting the flag in $_SESSION. That might lead to a race condition in which more than one "next page request" actually clears the cache. There is no good solution to the race condition but in this case at least clearing the type cache is merely a temporary performance hit, not a real problem.

However, I notice that node_get_types() has a reset argument:

function node_get_types($op = 'types', $node = NULL, $reset = FALSE);

Why not call node_get_types(NULL, NULL, TRUE) in content_type_create(), and then clear the CCK cache directly?

CommentFileSizeAuthor
#1 content-type-create-258127-1.patch1.07 KBbjaspan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bjaspan’s picture

Status: Active » Needs review
FileSize
1.07 KB

Here's a patch that uses node_get_types() $reset argument as I suggested above. It seems to work in my little test case.

I'm not sure if other places uses the content_menu_needs_rebuild() trick so I did not remove that code; content_type_create() merely no longer calls it because handles the cache clear directly.

KarenS’s picture

Status: Needs review » Fixed

Makes sense to me. I committed this and added a TODO to see if we really need the other content_menu_needs_rebuild() calls or if we can do it directly in the other places.

KarenS’s picture

I just got rid of the remaining places where content_menu_needs_rebuild() was used and rebuilt the menu directly. I also tried to limit the times menu_rebuild() is done to only when fields are added or deleted or the labels are changed (the labels are in the menu), and when content types change, so it isn't run any more than necessary. Previously I think it was happening on every field edit, which isn't really needed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.