Hi.
So, funny story. Month or two ago, I was searching web with google, but it very slow. So I do some research, and I find Google powered by Drupal. And Drupal open source, so I figure out what wrong!
So I set Drupal local, and I see what make it slow. But I get distracted! I see variable_get calls all over, everywhere. But there are two parameters! I do not like this. So I set up new hook_variables() that work well for this.
With this patch, Drupal system assume know about hook_variables(), which define variables' defaults. But sometimes module not loaded yet! So second parameter still there, but now is option.
The hook_variables hook work like this:
<?php
function hook_variables() {
return array(
'name_of_var' => 'default value of var',
);
}
?>
It also has fallback to deal with variable variables. For exampl, if a variable my_variable_3 not defined, it will look for defined variable my_variable.
It also can do variables that require callback, so as save time!
See:
<?php
function hook_variables() {
return array(
array(
'name' => 'my_var_name',
'callback' => 'url',
'arguments' => array(NULL, NULL, NULL, TRUE),
),
);
}
?>
Above will cause url(NULL, NULL, NULL, TRUE) to be called for the default of variable, but will not be executed until acually needed!
So, this do solve google problem after all. I am hoping this patch will be applied soon as possible so we can get google back working in my country. Thank you!
| Comment | File | Size | Author |
|---|---|---|---|
| qds97ckjqdf91cdsonrwvx.patch | 4.23 KB | jcyvwsobk |
Comments
Comment #1
cwgordon7 commentedBetter issue title.
Just so you know, Google is not powered by Drupal. But the patch you attached may be good. :)
Comment #2
kbahey commentedIn principle, I agree that we don't need a default on every variable_get() call. This violates the DRY (Don't Repeat Yourself) principle, and introduces errors (one area of the code has one default, the other has another, even due to a typo). So, having one argument is a good thing (TM).
I am not sure how this hook would address the problem of variables used in many modules (e.g. site_name, ...etc.), or if the same variable is defined in two modules each with a different value ...
Comment #3
chx commentedProblem is, the variable subsystem is available before the modules are loaded... also see http://lists.drupal.org/pipermail/development/2007-May/023665.html
Comment #4
cwgordon7 commented@chx: I think the patch leaves a layer of backwards compatibility there for variable_get calls before Drupal is fully bootstrapped. According to the inline comments, in these cases, a default value is still passed in, and the module_invoke_all call is avoided.
Dunno if this still needs work or needs review.
Comment #5
Crell commentedThis is a dupe of at least two other issues, I believe:
#79008: make variable prefetching optional
#145164: DX: Use hook_variable_info to declare variables and defaults
Let's someone pick this up and make it happen, please!