Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Forum module has a very nice caching pattern that should be factored out and developers urged to use it.
Comment | File | Size | Author |
---|---|---|---|
#19 | render_by_cache.diff | 2.93 KB | moshe weitzman |
#15 | drupal_render_cache_by_query.patch | 3.7 KB | chx |
#10 | drupal_render_cache_by_query.patch | 3.16 KB | chx |
#8 | drupal_render_cache_by_query.patch | 3.18 KB | chx |
#4 | drupal_render_cache_by_query.patch | 2.97 KB | chx |
Comments
Comment #1
catchThis simplifies the forum code a lot (that's currently the only place we use this pattern since #495968: Introduce drupal_render() cache pattern. Start using it for blocks was committed). there's no API change, just factoring out to a helper function. Looks good apart from some comment issues.
These should be @see a the end of the docblock instead of inline.
We must have a name for what this which isn't DBTNG? 'Select query object as returned by db_select()" enough?
Apart from that rtbc.
I'm on crack. Are you, too?
Comment #2
moshe weitzman CreditAttribution: moshe weitzman commentedNice.
Please doc the return value of the new function.
"is part of the cache key"
"is part of the cache key"
"cast", not casted
"in the cache key"
Comment #3
chx CreditAttribution: chx commentedFixed those comments.
Comment #4
chx CreditAttribution: chx commentedA few more comment fixes by Moshe. He asked about the
$granularity
default value, I am just copying fromfunction drupal_render_cid_parts($granularity = NULL)
.Comment #5
moshe weitzman CreditAttribution: moshe weitzman commentedthanks for the tweaks. nice little refactor.
Comment #6
sunTwo returns?
This looks a bit hard to grok... can't we keep #pre_render outside of the caching helper?
I'm on crack. Are you, too?
Comment #7
sunThis patch also doesn't seem to pass the original arguments to the new helper function?
This review is powered by Dreditor.
Comment #8
chx CreditAttribution: chx commentedFixed up the two returns and removed $cache_keys generation from forum.module. The pre_render is nice and dandy because it allows us to say "just use this function and it will bridge between $function and $function_pre_render" and if you need more just override #pre_render.
Comment #9
sunShouldn't we flip the position of $expire and $granularity?
I'd suspect that setting a custom granularity is more common than setting a custom cache lifetime.
Why is the block title removed?
This review is powered by Dreditor.
Comment #10
chx CreditAttribution: chx commentedtitle not removed. And no, I do not think we should as expire is very site / function specific. CACHE_TEMPORARY is highly arbitrary and often way too low.
Comment #11
sunIt's not clear to me what $args really is and for what it is used without reading the actual code.
I still think that most modules and stuff that use this function will rather want to pass custom $granularity and don't care for the $expire at all, but I'll let others chime in on that.
1) There should be a blank line between last @param and @return.
2) See http://drupal.org/node/1354 for proper formatting of Doxygen lists.
3) Trailing white-space here.
Why does this generic function point to forum module functions? Can be removed.
I'm on crack. Are you, too?
Comment #12
moshe weitzman CreditAttribution: moshe weitzman commentedThose @see lines are helpful pointers to real life usage of this function. We discussed those earlier.
$args is a hard to explain. we have rewritten it a couple times. please supply something better if you think the current one is insufficient.
Comment #13
sunThe @see lines added here are duplication. This function is called directly, so you get the same function reference like for every other function in the API output. To take an arbitrary example: http://api.drupal.org/api/function/drupal_render_cid_parts/7
Comment #14
moshe weitzman CreditAttribution: moshe weitzman commentedIts only duplicate when using api docs. When you are coding, it is quite helpful to have functions listed there. You can click into them and 'goto definition' or copy+search.
Comment #15
chx CreditAttribution: chx commentedFormatted doxygen list, removed the @see lines because we do not do them elsewhere and removed $args. See, I wrote a nice description saying this function creates a cache key based on $function, the string version of the query, the query arguments and drupal_render_cid_parts($granularity) and should this not be enough to make up a unique cache key then pass in extras -- but given we use query arguments it should indeed be enough. Yay, simplicity. The calling function can add to #cache['cache_keys'] should this prove to be false.
I am standing by that $expire is more important to granularity but also the fact that who cares :) ? It's an extremely minor detail IMO.
Comment #16
sunComment #17
webchickI think this patch makes sense, and it makes the code of forum module a heck of a lot more legible.
However, the PHPDoc there, while technically accurate, doesn't help me to understand when/where I would actually use this. We removed a comment in Forum module that explained we were caching the altered query to enable caching with node access. But I see no such hints in the PHPDoc for drupal_render_cache_by_query() (incidentally, we should put that comment back so that people reading Forum module know why we're calling drupal_render_cache_by_query()).
If you want to urge developers to use this liberally, you need to explain to them how to do it and when it's appropriate.
Comment #19
moshe weitzman CreditAttribution: moshe weitzman commentedEnhanced the PHPDoc a bit, and moved that code comment back to forum.module. This is all I can think of within the confines on PHPDoc. If this were a blog post, we could give elaborate examples and such. Back to RTBC. Please wait for bot before commit.
Comment #21
moshe weitzman CreditAttribution: moshe weitzman commentedIs bot broken? That re-test request is being ignored, and status page looks ok - http://qa.drupal.org/pifr/status
Comment #22
aspilicious CreditAttribution: aspilicious commentedjust reupload it
Comment #23
chx CreditAttribution: chx commentedCame back green.
Comment #24
webchickI still don't really find the docs sufficient here for new developers, but I would like to get this in before alpha 1 so that contrib can make use of it.
Committed to HEAD.
Please add to the module upgrade guide.
Comment #25
jhodgdonChanging tagging scheme - this goes in the module upgrade guide I guess
Comment #26
jhodgdonThis isn't an API *change* but an addition, so IMO it doesn't belong in the Drupal 6/7 module update guide http://drupal.org/update/modules/6/7.
That page just (or at least mostly) documents changes that would break D6 modules. No one could possibly read that page all the way through, and thereby learn about new functions they should be using -- the only way to use that page is to find out what to do when your module breaks, via control-f search for the function that isn't working any more.
So it probably needs to be documented in the module developer's guide or something like that?
I've also filed a follow-up issue because the PHP-doc for this function is not up to our doxygen standards and as webchick said in #24 it also doesn't really explain what the function is supposed to be used for, as far as I can tell.
#1133710: drupal_render_cache_by_query() doc is unclear and not standardized
Leaving this tagged as "Needs Documentation" because there seems to be a sentiment that it should go into some kind of a module developer guide somewhere? If someone can clarify what kind of thing should be written, that might help.
Comment #27
droplet CreditAttribution: droplet commentedthis issue bring a bug which fix in #914382: Contextual links incompatible with render cache
Comment #28
chx CreditAttribution: chx commentedComment #29
jhodgdonThis was just open for documentation, and I don't think, since 4 years have passed, that it's going to happen. The patch itself was applied years ago.