captcha_points_cache-7.x-1.3.patch
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
diff --git a/captcha.inc b/captcha.inc
index 934d72f..8b42fc0 100644
--- a/captcha.inc
+++ b/captcha.inc
@@ -64,6 +64,7 @@ function captcha_set_form_id_setting($form_id, $captcha_type) {
'warning'
);
}
+ cache_clear_all('captcha_points:' . $form_id,'cache_captcha');
}
/**
@@ -82,16 +83,19 @@ function captcha_set_form_id_setting($form_id, $captcha_type) {
* or in the form 'captcha/Math'.
*/
function captcha_get_form_id_setting($form_id, $symbolic = FALSE) {
- // Fetch setting from database.
- if (module_exists('ctools')) {
- ctools_include('export');
- $object = ctools_export_load_object('captcha_points', 'names', array($form_id));
- $captcha_point = array_pop($object);
- }
- else {
- $result = db_query("SELECT module, captcha_type FROM {captcha_points} WHERE form_id = :form_id",
- array(':form_id' => $form_id));
- $captcha_point = $result->fetchObject();
+
+ $cache_key = 'captcha_points:' . $form_id;
+
+ $cache = cache_get($cache_key,'cache_captcha');
+ $captcha_point = false;
+ if($cache && !empty($cache->data)){
+ $captcha_point = $cache->data;
+ }else{
+ $captcha_points = captcha_get_captcha_points();
+ if(isset($captcha_points[$form_id])){
+ $captcha_point = $captcha_points[$form_id];
+ cache_set($cache_key,$captcha_point,'cache_captcha',CACHE_PERMANENT);
+ }
}
// If no setting is available in database for the given form,
@@ -137,7 +141,7 @@ function captcha_get_captcha_points() {
$captcha_points = array();
$result = db_select('captcha_points', 'cp')->fields('cp')->orderBy('form_id')->execute();
foreach ($result as $captcha_point) {
- $captcha_points[] = $captcha_point;
+ $captcha_points[$captcha_point->form_id] = $captcha_point;
}
}
return $captcha_points;