Per: http://groups.drupal.org/node/4179

Attached patch is a start - takes >1000 lines out of node module (i.e. every page view).

Puts the node add/edit and revision handling callback in one file, while the admin pages go in another.
Also updates node_menu as appropriate.

Did some moderate testing - nothing obvious is broken by this. Obviously a menu rebuild is required.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pwolanin’s picture

FileSize
87.7 KB

moves a couple more functions to node.content_forms.inc

pwolanin’s picture

Passes all selected tests w/ the simpletest module using this patch to make simpletest work with 6.x: http://drupal.org/node/158148#comment-288985

Node Tests
2 test cases complete:
32 passes, 0 fails and 0 exceptions.
Page node creation
16 passes, 0 fails and 0 exceptions.

* Page node creation
* Unauthorized node view
Taxonomy
3 test cases complete:
68 passes, 0 fails and 0 exceptions.

* Vocabulary functions
* Term functions
* Taxonomy nodeapi
Crell’s picture

Title: Break up node module to use .inc files » Split up node module
Priority: Normal » Critical
Status: Needs review » Needs work

Renaming to match other issues, and bumping to critical because this is a core-required module.

node_admin_search() can be moved to the node.admin.inc file.

I'm not sure we should be putting page callbacks in content_types.inc. That seems to have other purposes. I'd rather keep page callbacks in their own files for cleanliness, and they should follow the naming convention. Things like node_add() should go in the pages.inc file.

I'm OK with leaving node_view() in the module, as it's probably the most-called page handler so it saves us a disk hit more often than not. node/%node/delete should go in a separate file, though.

Why node.content_forms.inc? Every other core module is using modulename.pages.inc. We should stick to that format for consistency, or else have node_view() in its very own node.pages.inc and the rest of the forms in node.content_forms.inc.

I've been leaving theme_ functions in the main .module file, because I don't fully know the potential issues with moving them. That's something to ask merlin about, since he and dvessel were doing all sorts of refactoring to theme functions, too, and I wanted to avoid clashing. Remember that anything except a page handler that needs to access a theme function will need to manually load the appropriate file first, which is icky. (How often that is for some theme functions I don't know, but I've been erring on the side of caution.)

Thanks for stepping up!

pwolanin’s picture

a quick follow-up: content_types.inc. was created in Drupal 5.x, so I didn't have any intention of changing what's already there.

I thought calling the 1st include file "content_forms" since it is handling everything for the node/add node/edit and node/x/revision/x paths which are basically forms for adding or changing content. Calling it "pages" seems much less informative.

Since I don't think anyone is going to need the node form theme function without the node form (or the admin form theme function without the admin form) I think it makes perfect sense to group them in the same .inc file.

Crell’s picture

I will defer to merlinofchaos and dvessel regarding the theme functions. If we do decide to move those out, that's something that should then be done to other modules, too. (Oh, refactoring...)

Dries had objected to modulename.feeds.inc for feed-based pages on the grounds that it was too obscure to break handlers up that far. That's why I've not been splitting things up further. Every other module has been using modulename.pages.inc, so it's a question of which way we want to be unclear/inconsistent. I'm inclined to lean toward standardized naming, but am willing to be overruled on that.

pwolanin’s picture

Status: Needs work » Needs review
FileSize
99.4 KB

Ok, here's an updated patch with various functions moved and re-ordered and with the include file rename as node.pages.inc. As before, I think a form's theme function should be in the same file with the form builder - anything else is nonsensical.

node_validate() and node_submit() need to be in the main module since they are called by blogapi (and maybe other modules) - the are now located with node_save().

node_admin_search() is a 2-line function - it seems counter-productive to require the loading and parsing of all the other page handlers for that.

Crell’s picture

Status: Needs review » Needs work

I spoke to merlin about the theme functions. Turns out the theme registry hook can specify a theme function lives in another file, if you specify both the file and function keys. Just having a file key would mean it's a template file, but both makes it a function in an include file. So it would look like (I think):

function node_theme() {
  return array(
    'foo' => array(
      'file' => 'node.pages.inc',
      'function' => 'foo',
    ),
   // ...
  );
}

Since that gets more code out of the .module file without resulting in another manual include_once(), let's do that. I guess I need to go back and do that to the other modules now, too. *sigh*

I've run into one or two other functions like that which have to be in the main file for edge cases, so those two don't surprise me.

I'd disagree regarding node_admin_search(). It's an admin page so is not often called. Leaving it in the .module file makes that page very slightly faster, but every other page very slightly slower since it has to parse that function. Moving it to the separate file makes that page slightly slower, and every other slightly faster. For a 2 line function slightly is a small value, but we should be consistent and apply the same logic to the whole module. Ideally if there is a pages file then the .module file should have no page handlers in it at all (except node_view(), because the trade-off goes the other direction on that one since it's so commonly called).

pwolanin’s picture

Status: Needs work » Needs review
FileSize
99.26 KB

Talked to merlinofchaos and dvessel on IRC - conclusion is that appropriate splitting of theme functions into .inc files is ok, especially you set the 'file' attribute in the theme registry. Note, there seems to be bug in theme.inc in , so we also have to set the 'function' attribute by hand.

So, here's another take on the patch - also move the (unused?) theme_node_log_message() back to node.module.

Crell’s picture

Hm, I think we cross-posted there. :-) I'll give this a test tonight. Thanks.

pwolanin’s picture

see also this issue about this theme registry: http://drupal.org/node/168028

pwolanin’s picture

FileSize
102.81 KB

@Crell - I didn't see your comment earlier - this patch also moves node_admin_search() to node.admin.inc.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Applies cleanly, I haven't found any pages it breaks, saves us about 1000 lines of code. I like. Thanks!

Dries’s picture

This patch needs a quick re-roll.

pwolanin’s picture

FileSize
99.58 KB

re-roll for block caching patch.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)