Since 2007, there has been considerable discussion about implementing a more sane Variable API since before Drupal 6 was in development. After much discussion and proposed patches in #145164: DX: Use hook_variable_info to declare variables and defaults, this issue was deferred to Drupal 8. Rather than bury this post in that thread that already has about 270 comments, let's open a new thread focused on what ideally the Variable API should look like in D8 and then get that implemented!!

Drupal core currently has its own variable_get/set/del functions with noted limitations. Variable API module differences has a brief summary of two existing contrib modules that address this issue. Likewise, drush has its own implementation of this variable API problem. Can we focus about what is wrong with the current variable process(es), what we ideally would like, the strengths and weaknesses of the various solutions and what needs to be implemented for the Variable API in D8? Then let's get it done!!

Comments

pillarsdotnet’s picture

+1

lars toomre’s picture

I come to this issue in the same way as agentrickard described in item #98 of #145164: DX: Use hook_variable_info to declare variables and defaults where I normally consolidate all variable defaults into some custom module default function set. I also have noticed that my sites are customarily loading many more variable/values pairs than are needed for the generation of a particular page. This slows down performance and I often have wondered how many of the variables (and with what frequency) are actually used across the last number of X page loads.

My custom module functions are generally of the format:

- MYMODULE_variable_get($variable, $options = NULL);
- MYMODULE_variable_set($variable, $value, $options = NULL);
- MYMODULE_variable_delete($variable, $options = NULL);
- MYMODULE_variable_init($variables, $options = NULL);

I store the variables in the $conf[] array in the format MYMODULE_$variable and hence can easily delete all module specific variables whenever the module is uninitialized and/or uninstalled. I would love to clean up the $conf[] array so that it is minimized for all page loads!!

I use the associative $options array to set such values as what the default value should be. I am sure that this can be expanded to set a flag that changes the behavior when in bootstrap mode (ie before the database layer is available) or when wanting to get a default defined via something like hook_variable_info().

moshe weitzman’s picture

Status: Active » Closed (duplicate)

Dupe of http://buytaert.net/configuration-management-in-drupal-8. Please participate the in the group mentioned there.

lars toomre’s picture

Rereading what I wrote above, let me expand upon one of my wish items about profiling information on what variables are used and with what frequency.

Ideally, in developer or debug mode, I would like to set a flag that would start recording in an array or data base all of the get/set information (and from what file/line number). This would be extremely useful in determining (rather than speculating) about what variables are used and what frequency on what page loads. A contrib module then could implement functions to manipulate this data. My hope in time is that we only load the minimal variables that are needed to actually create a specific page request.

There are obviously trade-offs between loading all variables in one call from a data base and loading the variables from the data base as individual items one after another. Perhaps we want to load some "smart" set of variables applicable to most page loads and then load "smart" increments depending on what particular page is being created?

There are trade-offs, but much of what I have seen indicates that we do not truly know what is used frequently and what is stored in conf[] as a matter of convenience rather than need. There also is the gapping issue of what to provide as a default value in the event that the variable does not yet currently exist in memory.

lars toomre’s picture

Status: Closed (duplicate) » Active

What node on drupal.org was that Moshe?

I did not see anything here on drupal.org that addresses this issue. Happy to contribute if the issue is identified. Thanks.

pillarsdotnet’s picture

So... drupal.org is the wrong place to discuss design decisions that affect the next version of drupal?

David_Rothstein’s picture

Subscribe.

If I remember right from the previous issue, the cleanest-looking approaches were also the ones with the worst performance... This is not a simple problem to solve :)

What is the goal of splitting this issue off from #145164: DX: Use hook_variable_info to declare variables and defaults? If it's to have a general discussion of possible architectures, then the g.d.o. group Moshe mentioned may be a better place. If it's to continue the same thing that went on there, then I'm not sure it really makes sense to have both issues open, so probably one of them should be closed.

lars toomre’s picture

@David_Rothstein, I am doubtful that many want to dig into a thread that is 3+ years old with more than 260 items. I thought starting with a fresh thread for Drupal 8 we might get some renewed focus on solving this continuing problem. I did not want to be so presumptuous to close another thread that has had little focus for the last nine months or so. You are welcome to close either one as long as something remains open to keep focus on this API issue.

The group that was referred to about configuration issues can be found at http://groups.drupal.org/node/134569. Reading through the various discussion items there, I do wonder whether the variable_get/set/del issues will get addressed as part of the larger configuration issue/needs.

lars toomre’s picture

Found #1059972: Very simple plugins subsystem which may make much of this issue an overlap. I am leaving this issue open for now as I investigate further.

JimmyAx’s picture

Subscribe

aaron’s picture

subscribe

lars toomre’s picture

There is some discussion about an intermediate fix to the variables API going on in the following issues:

#138544: Allow multiple variable deletes in variable_del()
#987768: [PP-1] Optimize variable caching
#317930: Allow multiple values in a single variable_set() call

Feel free to join the disucssion in #138544 about the format of multiple get/set/del() function formats. The key patch will be in #987768 to implement incremental caching of variables instead all of once as currently is implemented in D7.

avpaderno’s picture

What Moshe meant in his comment #3 is that such decisions are being taken already in another place.

gdd’s picture

There is a lot of discussion going on now around not just variables, but all configuration data, as part of the configuration management initiative. A writeup up a proposal I did is at

http://groups.drupal.org/node/149744

and it talks about what I would like to see for a new modern system of storing configuration. Please check out this proposal and comment or get involved, as it is likely to invalidate any number of core issues around the variable system.

berdir’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)

Yeah... I think we can close this ;)