Skip to content

Commit 9826331

Browse files
committed
Merge branch 'develop' into feature/monitor-client-api-refactoring
2 parents 3a1eb6c + 7d4da6c commit 9826331

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

bin/cache_tokens.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18-
ini_set('memory_limit', '512M');
18+
ini_set('memory_limit', '1G');
19+
20+
// define('ETHPLORER_SHOW_OUTPUT', 1);
1921

2022
require dirname(__FILE__) . '/../service/lib/ethplorer.php';
2123
$aConfig = require_once dirname(__FILE__) . '/../service/config.php';

service/lib/ethplorer.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ class Ethplorer {
136136

137137
protected $useOperations2 = FALSE;
138138

139+
protected $getTokensCacheCreation = FALSE;
140+
139141
/**
140142
* Constructor.
141143
*
@@ -977,7 +979,10 @@ public function getTokens($updateCache = false){
977979
return $this->aTokens;
978980
}
979981
$aResult = $this->oCache->get('tokens', false, true);
980-
if($updateCache || (false === $aResult)){
982+
if(!$this->getTokensCacheCreation && ($updateCache/* || (false === $aResult)*/)){
983+
// Recursion protection
984+
$this->getTokensCacheCreation = true;
985+
981986
evxProfiler::checkpoint('getTokens', 'START');
982987
$aPrevTokens = array();
983988
if($updateCache){
@@ -995,9 +1000,7 @@ public function getTokens($updateCache = false){
9951000
unset($aToken["_id"]);
9961001
$aResult[$address] = $aToken;
9971002
if(!isset($aPrevTokens[$address]) || ($aPrevTokens[$address]['transfersCount'] < $aToken['transfersCount'])){
998-
if(defined('ETHPLORER_SHOW_OUTPUT')){
999-
echo $address . " was recently updated (transfers count = " . $aToken['transfersCount'] . ")\n";
1000-
}
1003+
$this->_cliDebug($address . " was recently updated (transfers count = " . $aToken['transfersCount'] . ")");
10011004
$aResult[$address]['issuancesCount'] = $this->getContractOperationCount(array('$in' => array('issuance', 'burn', 'mint')), $address, FALSE);
10021005
$hc = $this->getTokenHoldersCount($address);;
10031006
if(FALSE !== $hc){
@@ -2081,7 +2084,7 @@ protected function _sortByTxCount($a, $b){
20812084
public function getTokenHistoryGrouped($period = 30, $address = FALSE, $type = 'daily', $cacheLifetime = 1800, $showEth = FALSE, $updateCache = FALSE){
20822085
$cache = 'token_history_grouped-' . ($address ? ($address . '-') : '') . $period . (($type == 'hourly') ? '-hourly' : '') . ($showEth ? '-eth' : '');
20832086
$result = $address ? $this->oCache->get($cache, false, true, $cacheLifetime) : $this->oCache->get($cache, false, true);
2084-
if(FALSE === $result || $updateCache){
2087+
if(($address && FALSE === $result) || $updateCache){
20852088
// Chainy
20862089
if($address && ($address == self::ADDRESS_CHAINY)){
20872090
return $this->getChainyTokenHistoryGrouped($period);
@@ -2796,9 +2799,16 @@ public function getAddressPriceHistoryGrouped($address, $updateCache = FALSE, $w
27962799
$result = false;
27972800
$updateCache = false;
27982801
}
2799-
2802+
28002803
if(FALSE === $result || $updateCache){
2801-
$aSearch = array('from', 'to', 'address');
2804+
2805+
$opCount = $this->countOperations($address, FALSE);
2806+
if($opCount >= 10000){
2807+
evxProfiler::checkpoint('getAddressPriceHistoryGrouped', 'FINISH', 'Address has >10000 operations, skip');
2808+
return FALSE;
2809+
}
2810+
2811+
$aSearch = array('from', 'to', 'address'); // @todo: research "addresses"
28022812
$aTypes = array('transfer', 'issuance', 'burn', 'mint');
28032813
$aResult = array();
28042814
$aContracts = array();
@@ -3313,7 +3323,8 @@ protected function getEthToken(){
33133323
}
33143324

33153325
protected function _cliDebug($message){
3316-
if(isset($this->aSettings['cliDebug']) && $this->aSettings['cliDebug'] && (php_sapi_name() === 'cli')){
3326+
$showDebug = ((isset($this->aSettings['cliDebug']) && $this->aSettings['cliDebug']) || defined('ETHPLORER_SHOW_OUTPUT')) && (php_sapi_name() === 'cli');
3327+
if($showDebug){
33173328
echo '[' . date("Y-m-d H:i:s") . '] ' . $message . "\n";
33183329
}
33193330
}

0 commit comments

Comments
 (0)