From 1cde7b06bca43c17e2fb279d95f72ba598d86f49 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 8 Feb 2023 15:54:42 +0100 Subject: [dozmod] Try to avoid race condition, output slow dmsd download --- modules-available/dozmod/api.inc.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3-55-g7522