@@ -23,6 +23,7 @@ class Quic extends Base
23
23
const TYPE_REG = 'reg ' ;
24
24
25
25
protected $ _summary ;
26
+ private $ _force = false ;
26
27
public function __construct ()
27
28
{
28
29
$ this ->_summary = self ::get_summary ();
@@ -33,54 +34,35 @@ public function __construct()
33
34
*
34
35
* @access public
35
36
*/
36
- public static function try_sync_config ()
37
- {
38
- self ::cls ()->try_sync_conf ();
39
- }
40
-
41
37
public function try_sync_conf ($ force = false )
42
38
{
43
- $ options = $ this ->get_options ();
39
+ if ($ force ) {
40
+ $ this ->_force = $ force ;
41
+ }
44
42
45
- if (!$ options [ self ::O_CDN_QUIC ] ) {
43
+ if (!$ this -> conf ( self ::O_CDN_QUIC ) ) {
46
44
if (!empty ($ this ->_summary ['conf_md5 ' ])) {
45
+ self ::debug ('❌ No QC CDN, clear conf md5! ' );
47
46
self ::save_summary (array ('conf_md5 ' => '' ));
48
47
}
49
48
return false ;
50
49
}
51
50
52
- // Security: Remove cf key in report
53
- $ secure_fields = array (self ::O_CDN_CLOUDFLARE_KEY , self ::O_OBJECT_PSWD );
54
- foreach ($ secure_fields as $ v ) {
55
- if (!empty ($ options [$ v ])) {
56
- $ options [$ v ] = str_repeat ('* ' , strlen ($ options [$ v ]));
57
- }
51
+ // Notice: Sync conf must be after `wp_loaded` hook, to get 3rd party vary injected (e.g. `woocommerce_cart_hash`).
52
+ if (!did_action ('wp_loaded ' )) {
53
+ add_action ('wp_loaded ' , array ($ this , 'try_sync_conf ' ), 999 );
54
+ self ::debug ('WP not loaded yet, delay sync to wp_loaded:999 ' );
55
+ return ;
58
56
}
59
- unset($ options [self ::O_MEDIA_LQIP_EXC ]);
60
- unset($ options [self ::O_API_KEY ]);
61
- unset($ options [self ::_VER ]);
62
-
63
- // Remove overflow multi lines fields
64
- foreach ($ options as $ k => $ v ) {
65
- if (is_array ($ v ) && count ($ v ) > 30 ) {
66
- $ v = array_slice ($ v , 0 , 30 );
67
- $ options [$ k ] = $ v ;
68
- }
69
- }
70
-
71
- // Rest url
72
- $ options ['_rest ' ] = function_exists ('rest_get_url_prefix ' ) ? rest_get_url_prefix () : apply_filters ('rest_url_prefix ' , 'wp-json ' );
73
- $ options ['_home_url ' ] = home_url ('/ ' );
74
57
75
- // Append hooks
58
+ $ options = $ this -> get_options ();
76
59
$ options ['_tp_cookies ' ] = apply_filters ('litespeed_vary_cookies ' , array ());
77
60
78
61
// Build necessary options only
79
62
$ options_needed = array (
80
63
self ::O_CACHE_DROP_QS ,
81
64
self ::O_CACHE_EXC_COOKIES ,
82
65
self ::O_CACHE_EXC_USERAGENTS ,
83
- self ::O_CACHE_FAVICON ,
84
66
self ::O_CACHE_LOGIN_COOKIE ,
85
67
self ::O_CACHE_VARY_COOKIES ,
86
68
self ::O_CACHE_MOBILE_RULES ,
@@ -90,16 +72,20 @@ public function try_sync_conf($force = false)
90
72
self ::O_CACHE_TTL_BROWSER ,
91
73
self ::O_IMG_OPTM_WEBP ,
92
74
self ::O_GUEST ,
93
- self ::O_GUEST_OPTM ,
94
75
'_tp_cookies ' ,
95
76
);
96
77
$ consts_needed = array ('WP_CONTENT_DIR ' , 'LSCWP_CONTENT_DIR ' , 'LSCWP_CONTENT_FOLDER ' , 'LSWCP_TAG_PREFIX ' );
97
78
$ options_for_md5 = array ();
98
79
foreach ($ options_needed as $ v ) {
99
80
if (isset ($ options [$ v ])) {
100
81
$ options_for_md5 [$ v ] = $ options [$ v ];
82
+ // Remove overflow multi lines fields
83
+ if (is_array ($ options_for_md5 [$ v ]) && count ($ options_for_md5 [$ v ]) > 30 ) {
84
+ $ options_for_md5 [$ v ] = array_slice ($ options_for_md5 [$ v ], 0 , 30 );
85
+ }
101
86
}
102
87
}
88
+
103
89
$ server_vars = $ this ->server_vars ();
104
90
foreach ($ consts_needed as $ v ) {
105
91
if (isset ($ server_vars [$ v ])) {
@@ -113,7 +99,7 @@ public function try_sync_conf($force = false)
113
99
$ conf_md5 = md5 (\json_encode ($ options_for_md5 ));
114
100
if (!empty ($ this ->_summary ['conf_md5 ' ])) {
115
101
if ($ conf_md5 == $ this ->_summary ['conf_md5 ' ]) {
116
- if (!$ force ) {
102
+ if (!$ this -> _force ) {
117
103
self ::debug ('Bypass sync conf to QC due to same md5 ' , $ conf_md5 );
118
104
return ;
119
105
}
@@ -124,7 +110,7 @@ public function try_sync_conf($force = false)
124
110
}
125
111
126
112
self ::save_summary (array ('conf_md5 ' => $ conf_md5 ));
127
- self ::debug ('sync conf to QC ' , $ options_for_md5 );
113
+ self ::debug ('sync conf to QC ' );
128
114
129
115
Cloud::post (Cloud::SVC_D_SYNC_CONF , $ options_for_md5 );
130
116
}
0 commit comments