Skip to content

Commit

Permalink
SmrSession: change static arrays to constants
Browse files Browse the repository at this point in the history
Since we use OPcache, it is better to do as much as possible at
compile time so it can be cached and reloaded. Const is compile
time, and static variable are runtime, so we switch to consts
when possible.
  • Loading branch information
hemberger committed Apr 28, 2018
1 parent 0b316ad commit 1ceef0d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Default/SmrSession.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(!defined('USING_AJAX'))
class SmrSession {
const ALWAYS_AVAILABLE = 999999;
const TIME_BEFORE_EXPIRY = 3600;
private static $URL_DEFAULT_REMAINING_PAGE_LOADS = array(
private const URL_DEFAULT_REMAINING_PAGE_LOADS = array(
'alliance_broadcast.php' => self::ALWAYS_AVAILABLE,
'alliance_forces.php' => self::ALWAYS_AVAILABLE,
'alliance_list.php' => self::ALWAYS_AVAILABLE,
Expand Down Expand Up @@ -113,7 +113,7 @@ class SmrSession {
'universe_create_warps.php' => self::ALWAYS_AVAILABLE
);

private static $URL_LOAD_DELAY = array(
private const URL_LOAD_DELAY = array(
'configure_hardware.php' => .4,
'forces_drop.php' => .4,
'forces_drop_processing.php' => .5,
Expand Down Expand Up @@ -165,7 +165,7 @@ class SmrSession {
if(!USING_AJAX && isset($_REQUEST['sn']) && isset(self::$var[$_REQUEST['sn']]) && !empty(self::$var[$_REQUEST['sn']])) {
$var = self::$var[$_REQUEST['sn']];
$currentPage = $var['url'] == 'skeleton.php' ? $var['body'] : $var['url'];
$loadDelay = isset(self::$URL_LOAD_DELAY[$currentPage]) ? self::$URL_LOAD_DELAY[$currentPage] : 0;
$loadDelay = isset(self::URL_LOAD_DELAY[$currentPage]) ? self::URL_LOAD_DELAY[$currentPage] : 0;
$initialTimeBetweenLoads = microtimeDiff(microtime(), $var['PreviousRequestTime']);
while(($timeBetweenLoads = microtimeDiff(microtime(), $var['PreviousRequestTime'])) < $loadDelay) {
$sleepTime = round(($loadDelay-$timeBetweenLoads)*1000000);
Expand Down Expand Up @@ -370,7 +370,7 @@ class SmrSession {
}
if(!isset($container['RemainingPageLoads'])) {
$pageURL = $container['url'] == 'skeleton.php' ? $container['body'] : $container['url'];
$container['RemainingPageLoads'] = isset(self::$URL_DEFAULT_REMAINING_PAGE_LOADS[$pageURL]) ? self::$URL_DEFAULT_REMAINING_PAGE_LOADS[$pageURL] : 1; // Allow refreshing
$container['RemainingPageLoads'] = isset(self::URL_DEFAULT_REMAINING_PAGE_LOADS[$pageURL]) ? self::URL_DEFAULT_REMAINING_PAGE_LOADS[$pageURL] : 1; // Allow refreshing
}

if($sn === false) {
Expand Down

0 comments on commit 1ceef0d

Please sign in to comment.