From 4a61d5329525e45e59d3ad86d6b9a786d06b42bb Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 13 Aug 2023 21:26:01 +0300 Subject: [PATCH] fix calendar cache timing --- src/public/index.php | 21 ++++++++++++--------- src/public/peer.php | 10 ++++++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/public/index.php b/src/public/index.php index 78182e1..ca54c20 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -48,13 +48,14 @@ foreach ($calendar->getNodes() as $day => $node) { $timeFrom = strtotime(sprintf('%s-%s-%s 00:00', date('Y', $requestTime), date('n', $requestTime), $day)); $timeTo = strtotime('+1 day', strtotime(sprintf('%s-%s-%s 00:00', date('Y', $requestTime), date('n', $requestTime), $day))); + $timeThis = strtotime('+1 day', strtotime(sprintf('%s-%s-%s 00:00', date('Y'), date('n'), $day))); $dbPeerTotalByTimeUpdated = $memory->getByMethodCallback( - $db, 'findPeerTotalByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time() + $db, 'findPeerTotalByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $timeThis ? 2592000 : MEMCACHED_TIMEOUT) + time() ); $dbPeerTotalByTimeAdded = $memory->getByMethodCallback( - $db, 'findPeerTotalByTimeAdded', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time() + $db, 'findPeerTotalByTimeAdded', [$timeFrom, $timeTo], ($timeTo <= $timeThis ? 2592000 : MEMCACHED_TIMEOUT) + time() ); // Add daily stats @@ -66,13 +67,14 @@ foreach ($calendar->getNodes() as $day => $node) { $timeFrom = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour)); $timeTo = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour + 1)); + $timeThis = strtotime(sprintf('%s-%s-%s %s:00', date('Y'), date('n'), $day, $hour + 1)); $dbPeerTotalByTimeUpdated = $memory->getByMethodCallback( - $db, 'findPeerTotalByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time() + $db, 'findPeerTotalByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $timeThis ? 2592000 : MEMCACHED_TIMEOUT) + time() ); $dbPeerTotalByTimeAdded = $memory->getByMethodCallback( - $db, 'findPeerTotalByTimeAdded', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time() + $db, 'findPeerTotalByTimeAdded', [$timeFrom, $timeTo], ($timeTo <= $timeThis ? 2592000 : MEMCACHED_TIMEOUT) + time() ); $calendar->addNode($day, $dbPeerTotalByTimeUpdated, sprintf(_('%s:00-%s:00 online %s'), $hour, $hour + 1, $dbPeerTotalByTimeUpdated), 'green', 1); @@ -82,16 +84,16 @@ foreach ($calendar->getNodes() as $day => $node) { break; case 'traffic': - // @TODO improve cache timing $timeFrom = strtotime(sprintf('%s-%s-%s 00:00', date('Y', $requestTime), date('n', $requestTime), $day)); $timeTo = strtotime('+1 day', strtotime(sprintf('%s-%s-%s 00:00', date('Y', $requestTime), date('n', $requestTime), $day))); + $timeThis = strtotime('+1 day', strtotime(sprintf('%s-%s-%s 00:00', date('Y'), date('n'), $day))); $dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback( - $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time() + $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $timeThis ? 2592000 : MEMCACHED_TIMEOUT) + time() ); $dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback( - $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time() + $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $timeThis ? 2592000 : MEMCACHED_TIMEOUT) + time() ); // Add daily stats @@ -103,13 +105,14 @@ foreach ($calendar->getNodes() as $day => $node) { $timeFrom = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour)); $timeTo = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour + 1)); + $timeThis = strtotime(sprintf('%s-%s-%s %s:00', date('Y'), date('n'), $day, $hour + 1)); $dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback( - $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time() + $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $timeThis ? 2592000 : MEMCACHED_TIMEOUT) + time() ); $dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback( - $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time() + $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $timeThis ? 2592000 : MEMCACHED_TIMEOUT) + time() ); $calendar->addNode($day, $dbPeerSessionSentSumByTimeUpdated, sprintf(_('%s:00-%s:00 ↑ %s'), $hour, $hour + 1, number_format($dbPeerSessionSentSumByTimeUpdated / 1000000, 3)), 'red', 1); diff --git a/src/public/peer.php b/src/public/peer.php index 6c1b393..b52adc6 100644 --- a/src/public/peer.php +++ b/src/public/peer.php @@ -50,13 +50,14 @@ foreach ($calendar->getNodes() as $day => $node) { $timeFrom = strtotime(sprintf('%s-%s-%s 00:00', date('Y', $requestTime), date('n', $requestTime), $day)); $timeTo = strtotime('+1 day', strtotime(sprintf('%s-%s-%s 00:00', date('Y', $requestTime), date('n', $requestTime), $day))); + $timeThis = strtotime('+1 day', strtotime(sprintf('%s-%s-%s 00:00', date('Y'), date('n'), $day))); $dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback( - $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time() + $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId], ($timeTo <= $timeThis ? 2592000 : MEMCACHED_TIMEOUT) + time() ); $dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback( - $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time() + $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId], ($timeTo <= $timeThis ? 2592000 : MEMCACHED_TIMEOUT) + time() ); // Add daily stats @@ -68,13 +69,14 @@ foreach ($calendar->getNodes() as $day => $node) { $timeFrom = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour)); $timeTo = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour + 1)); + $timeThis = strtotime(sprintf('%s-%s-%s %s:00', date('Y'), date('n'), $day, $hour + 1)); $dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback( - $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time() + $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId], ($timeTo <= $timeThis ? 2592000 : MEMCACHED_TIMEOUT) + time() ); $dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback( - $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time() + $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId], ($timeTo <= $timeThis ? 2592000 : MEMCACHED_TIMEOUT) + time() ); $calendar->addNode($day, $dbPeerSessionSentSumByTimeUpdated, sprintf(_('%s:00-%s:00 ↑ %s'), $hour, $hour + 1, number_format($dbPeerSessionSentSumByTimeUpdated / 1000000, 3)), 'red', 1);