Skip to content

Commit

Permalink
fixed id name generator for big data
Browse files Browse the repository at this point in the history
  • Loading branch information
sstarikov committed Mar 11, 2015
1 parent 52493aa commit a8813fb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
34 changes: 22 additions & 12 deletions DataTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,17 @@ function generateData(){
* in install_config.php for each module), and save the ID in the installData array.
*/
function generateId(){
if(($this->module == 'Users') || ($this->module == 'Teams')){
$this->installData['id'] = "'".'seed-'.$this->module . $this->count . "'";
$currentModule = $this->getAlias($this->module);
if(($currentModule == 'Users') || ($currentModule == 'Teams')){
$this->installData['id'] = "'" . 'seed-'. $currentModule . $this->count . "'";
}else{
$this->installData['id'] = "'".'seed-'.$this->module .$_SESSION['baseTime']. $this->count . "'";
$this->installData['id'] = "'" . 'seed-'. $currentModule .$_SESSION['baseTime'] . $this->count . "'";
}
if(strlen($this->installData['id']) > 36){
$this->installData['id'] = '\'seed-' . substr(md5($this->installData['id']), 0, -1). "'";
$moduleLength = strlen($currentModule);
$this->installData['id'] = '\'seed-' . $currentModule . substr(md5($this->installData['id']), 0, -($moduleLength + 1)). "'";
}
}
}

function clean(){
$this->installData = array();
Expand Down Expand Up @@ -676,11 +678,11 @@ function generateRelationships(){
* through $relationship['table']
*/
for($j = 0; $j < $thisToRelatedRatio; $j++){

$currentRelModule = $this->getAlias($relModule);
if(($relModule == 'Users') || ($relModule == 'Teams')){
$relId = 'seed-'.$relModule .$this->getRelatedLinkId($relModule);
$relId = 'seed-'. $currentRelModule .$this->getRelatedLinkId($relModule);
}else{
$relId = 'seed-'.$relModule .$_SESSION['baseTime'].$this->getRelatedLinkId($relModule);
$relId = 'seed-'. $currentRelModule .$_SESSION['baseTime'].$this->getRelatedLinkId($relModule);
}

$relOverridesStore = array();
Expand Down Expand Up @@ -796,10 +798,18 @@ function generateSeed($module, $field, $count){
*/
return 2*($this->str_sum($this->module . $field) + $this->count + $_SESSION['baseTime']);
}





/**
* Returns an alias to be used for id generation.
* @param $name - The current module
* @return string
*/
function getAlias($name) {
global $aliases;
$alias = isset ($aliases[$name]) ? $aliases[$name] : $name;
return $alias;
}

function str_sum($str){
$sum = 0;
for($i = strlen($str);$i--;){
Expand Down
6 changes: 6 additions & 0 deletions install_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@

);

$aliases = array(
'EmailAddresses' => 'Emadd',
'ProductBundles' => 'Prodb',
'Opportunities' => 'Oppty'
);

$tidbit_relationships['Users'] = array(
'Teams' => array(
'self' => 'user_id',
Expand Down

0 comments on commit a8813fb

Please sign in to comment.