Merge lp:~davidstrauss/pressflow/variable-write-through into lp:pressflow

Proposed by David Strauss
Status: Merged
Merged at revision: not available
Proposed branch: lp:~davidstrauss/pressflow/variable-write-through
Merge into: lp:pressflow
Diff against target: 71 lines (+30/-10)
1 file modified
includes/bootstrap.inc (+30/-10)
To merge this branch: bzr merge lp:~davidstrauss/pressflow/variable-write-through
Reviewer Review Type Date Requested Status
Pressflow Administrators Pending
Review via email: mp+16972@code.launchpad.net
To post a comment you must log in.
Revision history for this message
moshe weitzman (weitzman-tejasa) wrote :

I reviewed the proposal. Looks good to me.

68. By David Strauss

Add shell-based tests.

69. By David Strauss

Delete the rudimentary test files.

70. By David Strauss

Merge changes from mainline.

71. By David Strauss

Use locks to prevent stampedes on cache misses.

72. By David Strauss

Take advantage of the updated cache item instead of serializing rebuilds.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'includes/bootstrap.inc'
2--- includes/bootstrap.inc 2010-01-15 16:26:48 +0000
3+++ includes/bootstrap.inc 2010-01-15 21:15:20 +0000
4@@ -479,17 +479,27 @@
5 * with variable_set() as well as those explicitly specified in the configuration
6 * file.
7 */
8-function variable_init($conf = array()) {
9+function variable_init($conf = array(), $regenerate = FALSE) {
10 // NOTE: caching the variables improves performance by 20% when serving cached pages.
11- if ($cached = cache_get('variables', 'cache')) {
12+ if (!$regenerate && $cached = cache_get('variables', 'cache')) {
13 $variables = $cached->data;
14 }
15 else {
16- $result = db_query('SELECT * FROM {variable}');
17- while ($variable = db_fetch_object($result)) {
18- $variables[$variable->name] = unserialize($variable->value);
19- }
20- cache_set('variables', $variables);
21+ if (lock_acquire('variable_cache_regenerate')) {
22+ $result = db_query('SELECT * FROM {variable}');
23+ while ($variable = db_fetch_object($result)) {
24+ $variables[$variable->name] = unserialize($variable->value);
25+ }
26+ cache_set('variables', $variables);
27+ lock_release('variable_cache_regenerate');
28+ }
29+ else {
30+ // Wait for another request that is already doing this work.
31+ lock_wait('variable_cache_regenerate');
32+
33+ // Run the function again.
34+ return variable_init($conf, $regenerate);
35+ }
36 }
37
38 foreach ($conf as $name => $value) {
39@@ -537,9 +547,9 @@
40 @db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, $serialized_value);
41 }
42
43- cache_clear_all('variables', 'cache');
44-
45 $conf[$name] = $value;
46+
47+ variable_cache_rebuild();
48 }
49
50 /**
51@@ -557,9 +567,19 @@
52
53 unset($conf[$name]);
54
55- cache_set('variables', $conf);
56+ variable_cache_rebuild();
57 }
58
59+/**
60+ * Schedules a rebuild of the variable cache on shutdown.
61+ */
62+function variable_cache_rebuild() {
63+ static $shutdown_registered = FALSE;
64+ if (!$shutdown_registered) {
65+ register_shutdown_function('variable_init', array(), TRUE);
66+ $shutdown_registered = TRUE;
67+ }
68+}
69
70 /**
71 * Retrieve the current page from the cache.

Subscribers

People subscribed via source and target branches

to status/vote changes: