diff options
author | Simon Rettberg | 2023-02-08 15:54:42 +0100 |
---|---|---|
committer | Simon Rettberg | 2023-02-08 15:54:42 +0100 |
commit | 1cde7b06bca43c17e2fb279d95f72ba598d86f49 (patch) | |
tree | 31f571af1dc20642d8086348f35dd7b6822833cd /modules-available/dozmod | |
parent | [statistics] Fix notice on invalid array key access (diff) | |
download | slx-admin-1cde7b06bca43c17e2fb279d95f72ba598d86f49.tar.gz slx-admin-1cde7b06bca43c17e2fb279d95f72ba598d86f49.tar.xz slx-admin-1cde7b06bca43c17e2fb279d95f72ba598d86f49.zip |
[dozmod] Try to avoid race condition, output slow dmsd download
Diffstat (limited to 'modules-available/dozmod')
-rw-r--r-- | modules-available/dozmod/api.inc.php | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/modules-available/dozmod/api.inc.php b/modules-available/dozmod/api.inc.php index c71ea946..6b9d68c8 100644 --- a/modules-available/dozmod/api.inc.php +++ b/modules-available/dozmod/api.inc.php @@ -34,7 +34,10 @@ function cache_key_to_filename($key) function cache_put($key, $value) { $filename = cache_key_to_filename($key); - file_put_contents($filename, $value); + // Try to avoid another client concurrently accessing the cache seeing an empty file + $tmp = $filename . '-' . mt_rand(); + file_put_contents($tmp, $value); + rename($tmp, $filename); } function cache_has($key) @@ -179,7 +182,12 @@ function getListForLocations($locationIds, $raw) if ($examMode) { $url .= '&exams'; } + $t = microtime(true); $value = Download::asString($url, 60, $code); + $t = microtime(true) - $t; + if ($t > 5) { + error_log("Download of lecture list took $t ($code)"); + } if ($value === false || $code < 200 || $code > 299) return false; cache_put($rawKey, $value); @@ -207,7 +215,12 @@ function _getVmData($lecture_uuid, $subResource = false) if ($subResource !== false) { $url .= '/' . $subResource; } + $t = microtime(true); $response = Download::asString($url, 60, $code); + $t = microtime(true) - $t; + if ($t > 5) { + error_log("Download of $subResource took $t ($code)"); + } if ($code < 200 || $code > 299) return (int)$code; return $response; |