Browse Source

reduce server load by caching past results in the active month for 30 days

yggdrasil-0.4.7
ghost 1 year ago
parent
commit
0e748f97df
  1. 16
      src/public/index.php
  2. 8
      src/public/peer.php

16
src/public/index.php

@ -50,11 +50,11 @@ foreach ($calendar->getNodes() as $day => $node) {
$timeTo = strtotime('+1 day', 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)));
$dbPeerTotalByTimeUpdated = $memory->getByMethodCallback( $dbPeerTotalByTimeUpdated = $memory->getByMethodCallback(
$db, 'findPeerTotalByTimeUpdated', [$timeFrom, $timeTo] $db, 'findPeerTotalByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time()
); );
$dbPeerTotalByTimeAdded = $memory->getByMethodCallback( $dbPeerTotalByTimeAdded = $memory->getByMethodCallback(
$db, 'findPeerTotalByTimeAdded', [$timeFrom, $timeTo] $db, 'findPeerTotalByTimeAdded', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time()
); );
// Add daily stats // Add daily stats
@ -68,11 +68,11 @@ foreach ($calendar->getNodes() as $day => $node) {
$timeTo = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour + 1)); $timeTo = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour + 1));
$dbPeerTotalByTimeUpdated = $memory->getByMethodCallback( $dbPeerTotalByTimeUpdated = $memory->getByMethodCallback(
$db, 'findPeerTotalByTimeUpdated', [$timeFrom, $timeTo] $db, 'findPeerTotalByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time()
); );
$dbPeerTotalByTimeAdded = $memory->getByMethodCallback( $dbPeerTotalByTimeAdded = $memory->getByMethodCallback(
$db, 'findPeerTotalByTimeAdded', [$timeFrom, $timeTo] $db, 'findPeerTotalByTimeAdded', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time()
); );
$calendar->addNode($day, $dbPeerTotalByTimeUpdated, sprintf(_('%s:00-%s:00 online %s'), $hour, $hour + 1, $dbPeerTotalByTimeUpdated), 'green', 1); $calendar->addNode($day, $dbPeerTotalByTimeUpdated, sprintf(_('%s:00-%s:00 online %s'), $hour, $hour + 1, $dbPeerTotalByTimeUpdated), 'green', 1);
@ -87,11 +87,11 @@ foreach ($calendar->getNodes() as $day => $node) {
$timeTo = strtotime('+1 day', 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)));
$dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback( $dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback(
$db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo] $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time()
); );
$dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback( $dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback(
$db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo] $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time()
); );
// Add daily stats // Add daily stats
@ -105,11 +105,11 @@ foreach ($calendar->getNodes() as $day => $node) {
$timeTo = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour + 1)); $timeTo = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour + 1));
$dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback( $dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback(
$db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo] $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time()
); );
$dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback( $dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback(
$db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo] $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time()
); );
$calendar->addNode($day, $dbPeerSessionSentSumByTimeUpdated, sprintf(_('%s:00-%s:00 &uarr; %s'), $hour, $hour + 1, number_format($dbPeerSessionSentSumByTimeUpdated / 1000000, 3)), 'red', 1); $calendar->addNode($day, $dbPeerSessionSentSumByTimeUpdated, sprintf(_('%s:00-%s:00 &uarr; %s'), $hour, $hour + 1, number_format($dbPeerSessionSentSumByTimeUpdated / 1000000, 3)), 'red', 1);

8
src/public/peer.php

@ -52,11 +52,11 @@ foreach ($calendar->getNodes() as $day => $node) {
$timeTo = strtotime('+1 day', 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)));
$dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback( $dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback(
$db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId] $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time()
); );
$dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback( $dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback(
$db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId] $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time()
); );
// Add daily stats // Add daily stats
@ -70,11 +70,11 @@ foreach ($calendar->getNodes() as $day => $node) {
$timeTo = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour + 1)); $timeTo = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour + 1));
$dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback( $dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback(
$db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId] $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time()
); );
$dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback( $dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback(
$db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId] $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo, $requestPeerId], ($timeTo <= $requestTime ? 2592000 : MEMCACHED_TIMEOUT) + time()
); );
$calendar->addNode($day, $dbPeerSessionSentSumByTimeUpdated, sprintf(_('%s:00-%s:00 &uarr; %s'), $hour, $hour + 1, number_format($dbPeerSessionSentSumByTimeUpdated / 1000000, 3)), 'red', 1); $calendar->addNode($day, $dbPeerSessionSentSumByTimeUpdated, sprintf(_('%s:00-%s:00 &uarr; %s'), $hour, $hour + 1, number_format($dbPeerSessionSentSumByTimeUpdated / 1000000, 3)), 'red', 1);

Loading…
Cancel
Save