Skip to content

Commit

Permalink
optimize apis
Browse files Browse the repository at this point in the history
  • Loading branch information
deemru committed Sep 18, 2023
1 parent 991901c commit ff45720
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function apiexit( $code, $json )
$json = $RO->getLastHeightTimestamp();
if( $json === false )
apiexit( 503, [ 'code' => 503, 'message' => 'database unavailable' ] );
apiexit( 200, $json[0] + 1 );
apiexit( 200, $json[0] );
}
else
if( $f === 'alive' )
Expand All @@ -113,12 +113,13 @@ function apiexit( $code, $json )
$json = $RO->getLastHeightTimestamp();
if( $json === false )
apiexit( 503, [ 'code' => 503, 'message' => 'database unavailable' ] );
$now = (int)microtime( true );
$now = time();
$dbts = $json[1];
$lag = $now - $dbts;
if( $lag > 600 )
apiexit( 503, [ 'code' => 503, 'message' => "too big lag: $now - $dbts = $lag > 600" ] );
apiexit( 200, $lag );
$diff = $now - $dbts;
$threshold = $arg === false ? 600 : intval( $arg );
if( $diff > $threshold )
apiexit( 503, [ 'code' => 503, 'message' => "too big diff: $now - $dbts = $diff > $threshold" ] );
apiexit( 200, $diff );
}

exit( http_response_code( 404 ) );
Expand Down

0 comments on commit ff45720

Please sign in to comment.