Updated: Comment #24
Problem/Motivation
Some module implements hook_node_load() which stores a static cache of the information it adds to the nodes. The user saves/edits a node using node_save() and want's to re-load the node using the $reset parameter. Because the hook is still using its own static cache, it will return stale data.
Proposed resolution
Document that hook_entity_load(), and the various hook_something_load() hooks should always be treated as 'fresh' and never statically cache it's data. The only time those hooks will get invoked if is $reset is TRUE or a new entity that hasn't been seen or retrieved yet is loaded.
Remaining tasks
The documentation has to be written but firstly, the task has to be assigned to someone.
User interface changes
None.
API changes
None.
Original report by Dave Reid
Comments
Comment #1
sven.lauer commentedSeems like a good novice task.
Comment #2
jhodgdontagging
Comment #4
lnunesbrIt's a good way to start contributing to core... I'm on it...
Comment #5
jhodgdonThanks lnunesbr! The first step is to assign the issue to yourself (using the "Assigned" field above the new comment form).
Comment #6
aLearner commentedHi,
Is anyone working on this issue? If not, I'm happy to take the ball on this.
Comment #7
jhodgdonaLearner: Apparently not. Please assign it to yourself. :)
Comment #8
aLearner commentedjhodgdon,
Roger that.
Also, any pointers on how I should go about identifying the files that need to be documented with the change? I'm not a grep guru. I haven't been able to figure out how to get Eclipse working with Drupal either. A nudge in the right direction would be greatly appreciated!
Comment #9
jhodgdonSee http://drupal.org/node/144223 for information on how to update API docs in general (and how to figure out where the files are).
See http://drupal.org/novice if you need help with the git/patching process.
Comment #10
aLearner commentedjhodgdon,
Thank you for the pointers. I'm waiting for my patch to be reviewed and thought I could help with documentation (since this is an area that's also new to me (along with everything else)) in the interim.
I'll go through both links carefully. The second one I've seen before - the first one I haven't seen at all.
Comment #11
jhodgdonExcellent! You might also be interested in http://drupal.org/core-office-hours
Comment #12
aLearner commentedjhodgdon,
Thank you. Yes, I'm aware of office hours and have been attending them.
Comment #13
jhodgdonThere's no patch here, so this issue is still "active".
Comment #14
aLearner commentedjhodgdon,
OK. Cool. Thanks for fixing this.
Comment #15
jthorson commentedHere's the result of a search for 'function hook_*_load(' from the /core/modules directory in Drupal 8.
The ##: represents the line number of the file where the function was found.
Comment #16
aLearner commentedjthorson,
Thank you for furnishing this report. It's very helpful. Thanks again.
Comment #17
aLearner commentedOK. So I looked at the comments for the following function
/core/modules/comment
comment.api.php
54: function hook_comment_load($comments) {
They read
I was wondering what I need to change them to, after reading Dave Reid's comments, since what's expressed as part of the solution is not clear to me. Would something like this, for example, be acceptable?
Comment #18
jhodgdonSomething *like* that, yes... Let's see if we can write it a little better and follow documentation standards though. :) Things that I noticed:
- "it's" should be "its"
- I think it goes past 80-character lines
- Doesn't use list formatting -- actually I think we shouldn't even use a list here.
- Refers to $reset, which isn't a parameter to this function. It needs to say something more like "This hook will only be invoked from whatever_function() if its $reset argument is TRUE, or if new comments that haven't been retrieved yet are requested."... and you'd need to figure out what whatever_function() is.
- I don't really like the "treated as 'fresh'" terminology because I don't know what it means.
- Don't put 'hook_comment_load' function in quotes. Actually it should say something like "Functions that implement this hook should ...".
Documentation standards for reference:
http://drupal.org/node/1354
Comment #19
aLearner commentedjhodgdon,
Thank you for taking the time to go through my post and get back to me with your suggestion. I really appreciate it.
Right. Sorry about that.
OK.
Understood.
(a) And how would I figure out what 'whatever_function' is?
(b) Also, do you mean
'...or if new contents that haven't been retrieved yet are requested...'
Neither do I, actually. I took the terminology straight from the original poster. Things would be easier for me to comment if I understood what it is I'm trying to comment. This is not clear to me. Any help on this front would be greatly appreciated.
All right.
Thank you for the reference to the documentation link. I'll certainly go through.
Thanks again.
Comment #20
jhodgdonOK, removing the Novice tag.... aLearner: feel free to pursue this, but I'm realizing it is a bit more involved than the average Novice-tagged issue. It will require whoever takes this issue on to learn about what these hooks do and how they are invoked, in order to write good documentation for this.
Regarding the "whatever" functions... What's needed here is that for each of these hooks, someone needs to figure out when they are invoked, which is usually within a function named entity_load(), entity_load_multiple(), node_load(), comment_load(), etc. Some of these hooks may be invoked from more than one function. And the idea is that if those functions have a $reset=TRUE argument, then the hook will be invoked, and otherwise those functions are using a cache and the previously-loaded versions of the node, comment, etc. will be loaded.
Somehow, in some readable format, this information needs to get into the documentation of the hooks listed in comment #15 above. I think that the text added to each hook should be specific to each hook. So for instance in hook_comment_load(), it should refer to comments, and in hook_node_load(), it should refer to nodes.
Comment #21
aLearner commentedjhodgdon,
Thank you for your detailed reply. I'll certainly try to do this if you think a total novice like me can indeed do it. Perhaps it'll be a great learning opportunity to dig deep and find out what the hooks do and how they are invoked? Admittedly, I don't know anything at this point but I'm very eager to learn and to contribute.
Thanks also for the detailed explanation on the 'whatever' functions.
What do you think would be a good, next step, then?
Comment #22
jhodgdonYou'll probably need to get some help/orientation at Core Office Hours as a next step.
Comment #23
aLearner commentedThis is not moving forward since maybe I'm just too novice to take this on (despite being present during office hours). I'm going ahead and unassigning myself this so that perhaps someone that has the knowledge / experience can perhaps push things forward.
Comment #24
PavanL commentedComment #25
jhodgdonAt this point, I do not think this is an issue any more. The Drupal 8 cache system has changed radically, and people should be using cache tags etc. if they are developing with the cache system. So, moving this to Drupal 7.