Skip to content

Commit 4cbb7b2

Browse files
Merge branch 'develop' of https://github.com/untrobotics/website into develop
2 parents 6e737b8 + 75333f7 commit 4cbb7b2

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

api/api-cache.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,27 @@
77
* @param mixed ...$args The endpoint arguments for the API request
88
* @return array|null The first entry that matches or null if no entry exists
99
*/
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));
1112
global $db;
1213
$q = $db->query("
1314
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
2116
FROM
22-
api_cache
17+
api_cache cache
2318
INNER JOIN
24-
outgoing_request_cache_config
19+
outgoing_request_cache_config config
2520
ON
26-
api_cache.config_id = outgoing_request_cache_config.id
21+
cache.config_id = config.id
2722
WHERE
28-
endpoint = '{$db->real_escape_string($endpoint)}'
23+
config.endpoint = '{$db->real_escape_string($endpoint)}'
2924
AND
30-
endpoint_args = '{$db->real_escape_string(serialize($args))}'
25+
cache.endpoint_args = '{$db->real_escape_string(serialize($args))}'
3126
");
3227
if ($q) {
33-
$r = $q->fetch_array(MYSQLI_ASSOC);
34-
return $r;
28+
return $q->fetch_field();
3529
}
36-
return null;
30+
return false;
3731
}
3832

3933
class CacheResult
@@ -141,9 +135,8 @@ function get_valid_cache_entry(string $endpoint, $ch, ...$args) {
141135
*/
142136
function cache(string $endpoint, string $content, int $config_id, ...$args) {
143137
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) {
147140
$query_string = '
148141
UPDATE
149142
api_cache
@@ -167,7 +160,7 @@ function cache(string $endpoint, string $content, int $config_id, ...$args) {
167160
({$config_id},
168161
UTC_TIMESTAMP,
169162
UTC_TIMESTAMP,
170-
'{$db->real_escape_string(implode('|', $args))}',
163+
'{$db->real_escape_string(serialize($args))}',
171164
COMPRESS('{$db->real_escape_string($content)}'))";
172165
}
173166
$q = $db->query($query_string);

0 commit comments

Comments
 (0)