7
7
* @param mixed ...$args The endpoint arguments for the API request
8
8
* @return array|null The first entry that matches or null if no entry exists
9
9
*/
10
- function get_cached_api_response (string $ endpoint , ...$ args ): ?array {
10
+ function get_cached_api_response (string $ endpoint , ...$ args ) {
11
+ error_log ("$ endpoint -> " . serialize ($ args ));
11
12
global $ db ;
12
13
$ q = $ db ->query ("
13
14
SELECT
14
- id,
15
- config_id,
16
- last_sucessfully_retrieved,
17
- last_attempted_retrieval,
18
- retry_count,
19
- endpoint_args,
20
- UNCOMPRESS(content) AS content
15
+ id
21
16
FROM
22
- api_cache
17
+ api_cache cache
23
18
INNER JOIN
24
- outgoing_request_cache_config
19
+ outgoing_request_cache_config config
25
20
ON
26
- api_cache .config_id = outgoing_request_cache_config .id
21
+ cache .config_id = config .id
27
22
WHERE
28
- endpoint = ' {$ db ->real_escape_string ($ endpoint )}'
23
+ config. endpoint = ' {$ db ->real_escape_string ($ endpoint )}'
29
24
AND
30
- endpoint_args = ' {$ db ->real_escape_string (serialize ($ args ))}'
25
+ cache. endpoint_args = ' {$ db ->real_escape_string (serialize ($ args ))}'
31
26
" );
32
27
if ($ q ) {
33
- $ r = $ q ->fetch_array (MYSQLI_ASSOC );
34
- return $ r ;
28
+ return $ q ->fetch_field ();
35
29
}
36
- return null ;
30
+ return false ;
37
31
}
38
32
39
33
class CacheResult
@@ -141,9 +135,8 @@ function get_valid_cache_entry(string $endpoint, $ch, ...$args) {
141
135
*/
142
136
function cache (string $ endpoint , string $ content , int $ config_id , ...$ args ) {
143
137
global $ db ;
144
- $ r = get_cached_api_response ($ endpoint , ...$ args );
145
- if ($ r ) {
146
- $ id = $ r ['id ' ];
138
+ $ id = get_cached_api_response ($ endpoint , ...$ args );
139
+ if ($ id ) {
147
140
$ query_string = '
148
141
UPDATE
149
142
api_cache
@@ -167,7 +160,7 @@ function cache(string $endpoint, string $content, int $config_id, ...$args) {
167
160
( {$ config_id },
168
161
UTC_TIMESTAMP,
169
162
UTC_TIMESTAMP,
170
- ' {$ db ->real_escape_string (implode ( ' | ' , $ args ))}',
163
+ ' {$ db ->real_escape_string (serialize ( $ args ))}',
171
164
COMPRESS(' {$ db ->real_escape_string ($ content )}')) " ;
172
165
}
173
166
$ q = $ db ->query ($ query_string );
0 commit comments