The new category_resave module is now an important part of 5.x->6.x upgrade path. If someone previously used category_display module for TOC trees (and the like), but not category_menu (I've disabled that on my site for years, due to it's serious bugs on 5.x and below), and they want to keep the behavior after upgrade, they need to enable new category_menu, and rebuild the structure using category_resave. (BTW, this might be mentioned somewhere, perhaps UPGRADE.txt is a good place?)

Unfortunately, the current state of category_resave is feeling a bit unfinished, and nowhere near usable, due to the following two problems:

- The UI is very confusing. There's no mention anywhere, about how to use this module, and when enabled, it doesn't show up on any of the expected places like admin/settings/category_resave, admin/content/category/resave, operations on node administration screen or the like. I finally had to read through the code, to figure out where to look for the functionality. Really, having to enable a block on the blocks administration page, and then performing administrative tasks from a sidebar is *very* unusual. So my proposal here is: Turn the form into a normal local task (tab) on the category administration page. (It also means simplification of the code - hook_block() implementation not needed anymore.)

- The module doesn't work for large sites, due to php timeout. For example, my site have about 1000 nodes assigned under some containers, but category_resave only saves <10 nodes before timing out. It definitely needs to use the Batch API. I implemented this, so now the function category_resave_container() only just collects a list of nodes into a batch, which is then run through the Batch API (takes half a hour on my site!).

I also cleaned up some obvious cruft - there seems to be leftovers from something like redirection to a dedicated processing page (category_resave/###), which is not used (all the processing was called directly from the form submit handler, already), and doesn't work anyway (the container id given as argument not processed at all). Also the $form['#action'] and drupal_get_destination() stuff did quite nothing. Since the Batch API integrates nicely into a form submit handler, and it was only accessible through a form submit already, I left it at that, and removed the other cruft.

Then, I see no point in the additional check for nodes (assigned content) in category_resave_container(): If we already selected only nodes assigned to the given category (with the query), why collect categories for each of these nodes again, and check whether the first of them is what we're processing? If the node was triggered for re-save by more assigned categories, the check for already processed nodes will catch that anyway.

Attaching a patch, and since it's bigger than the actual module, attaching also the .module file for reference and easier review.

Comments

JirkaRybka’s picture

StatusFileSize
new8.8 KB

Improved patch:

While experimenting with upgrade of my site, I learned how scary it might be to re-save all categorized nodes on a larger site. My site have tens and tens of categories (not really nice to re-save manually), and thousands of categorized nodes (SCARY!). And the only thing I need to do on the said site is: Refresh generated menu items for containers and categories (after category_menu got installed), to make TOC trees show, and to have no need to maintain custom links for categories in navigation menu anymore.

(Background on the use case: I didn't enable generated menu links for any assigned contents - it makes no sense to have generated menu links for thousands of nodes, as the expanded navigation menu in a sidebar will be scary and three times longer than the actual node viewed, and the menu administration screen will get unusable (despite all the improvements of D6 menu system, it's still not scalable to such a number of items, due to browser/JavaScript performance issues, having no pager on that page, and tabledrag being slow). This is one of the major reasons why Category module is still really needed for hiearchic navigation to my content.)

So, as for category_resave module, I only really need it to re-save containers and categories, without assigned nodes. So, I added a checkbox, allowing the user to choose whether to re-save nodes or not (defaults to yes). On large sites, this may be a huge time saver, if just regenerating category/container menu items: One of my containers went from 827 re-saved nodes (more than 1 hour processing) to 33 nodes (just a few minutes).

I also added a description for that box, mentioning the use case, and a warning that re-saving on large sites takes quite a while.

Jaza’s picture

Status: Needs review » Fixed

Nice work, JirkaRybka! Committed to HEAD.

All up, I like the approach you've taken. I was a bit reluctant to get rid of category_resave's block - I put its UI in a block, because I found it most convenient to be able to run the resave regularly from any page, rather than having to navigate to an admin page - but with the new batch API-powered UI, a page really makes sense and a block doesn't. If you need to run resave regularly, you can always just keep the resave page open in another tab of your browser, with the new UI.

Status: Fixed » Closed (fixed)

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