I just happened to run into an issue with the static vars with taxonomy_get_tree() and need to be able to flush these variables. I realize this may not be a problem for other people and that this will not be placed in 5.7 but it does have some bearing and might be thought about with 7.x.

Please see this comment for further description

function taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL, $flush = FALSE) {
  if (!$flush) {
    static $children, $parents, $terms;
  }
...

Thanks
Jonathan

Comments

grndlvl’s picture

grndlvl’s picture

StatusFileSize
new862 bytes

Oops sorry wrong patch

drumm’s picture

Version: 5.7 » 7.x-dev

New features must be added only to the current development version. Since this is a small API addition, there is a small chance it might be added to stable versions.

catch’s picture

Category: feature » bug
StatusFileSize
new1.17 KB

Core normally uses $reset in these situations, so re-rolled with that.

catch’s picture

catch’s picture

StatusFileSize
new6.79 KB

Here's a slight refinement which only flushes the static for $vid as opposed to all of them, which is important for this nastily expensive function.

I added some basic testing of taxonomy_get_tree into taxonomy.test in amongst the other hierarchy tests. However, I was unable to make it break without the reset - so any ideas on how to reproduce the errors in 306891 would be great.

catch’s picture

StatusFileSize
new6.96 KB

Some test fixes via Damz in irc, still fails to fail though.

wim leers’s picture

Subscribing.

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch failed testing.

jonathan_hunt’s picture

FYI, I just utilised the patch at #7 in 5.14; I'm importing multiple terms during a single page invocation and got caught by the static caching within taxonomy_get_tree(). Thanks for your work.

catch’s picture

Had to add this reset in #144969: taxonomy_term_count_nodes returns wrong count (+ tests) which comes with tests.

catch’s picture

Status: Needs work » Closed (duplicate)

Duplicate of that issue now.