Skip to content

Commit

Permalink
adding support for 64 bit primary keys for fact tables. Open-Web-Anal…
Browse files Browse the repository at this point in the history
  • Loading branch information
padams committed Jan 6, 2012
1 parent eb1d6ea commit 7e84dbd
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 11 deletions.
5 changes: 2 additions & 3 deletions modules/base/classes/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ function replaceProperties($properties) {
*/
function set_guid() {

return crc32(getmypid().time().rand());

return owa_lib::generateRandomUid();
}

/**
Expand Down Expand Up @@ -284,7 +283,7 @@ function getGuid() {

function getSiteSpecificGuid($site_id) {

return crc32(getmypid().time().rand().$site_id);
return owa_lib::generateRandomUid();
}


Expand Down
64 changes: 60 additions & 4 deletions modules/base/js/owa.js
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,61 @@ OWA.util = {
return typeof(input)=='object'&&(input instanceof Array);
},

// Returns input string padded on the left or right to specified length with pad_string
//
// version: 1109.2015
// discuss at: http://phpjs.org/functions/str_pad
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + namespaced by: Michael White (http://getsprink.com)
// + input by: Marco van Oort
// + bugfixed by: Brett Zamir (http://brett-zamir.me)
// * example 1: str_pad('Kevin van Zonneveld', 30, '-=', 'STR_PAD_LEFT');
// * returns 1: '-=-=-=-=-=-Kevin van Zonneveld'
// * example 2: str_pad('Kevin van Zonneveld', 30, '-', 'STR_PAD_BOTH');
// * returns 2: '------Kevin van Zonneveld-----'
str_pad : function (input, pad_length, pad_string, pad_type) {

var half = '',
pad_to_go;

var str_pad_repeater = function (s, len) {
var collect = '',
i;

while (collect.length < len) {
collect += s;
}
collect = collect.substr(0, len);

return collect;
};

input += '';
pad_string = pad_string !== undefined ? pad_string : ' ';

if (pad_type != 'STR_PAD_LEFT' && pad_type != 'STR_PAD_RIGHT' && pad_type != 'STR_PAD_BOTH') {
pad_type = 'STR_PAD_RIGHT';
}
if ((pad_to_go = pad_length - input.length) > 0) {
if (pad_type == 'STR_PAD_LEFT') {
input = str_pad_repeater(pad_string, pad_to_go) + input;
} else if (pad_type == 'STR_PAD_RIGHT') {
input = input + str_pad_repeater(pad_string, pad_to_go);
} else if (pad_type == 'STR_PAD_BOTH') {
half = str_pad_repeater(pad_string, Math.ceil(pad_to_go / 2));
input = half + input + half;
input = input.substr(0, pad_length);
}
}

return input;
},

zeroFill : function(number, length) {

return OWA.util.str_pad( number, length, '0', 'STR_PAD_LEFT');
},

// Returns true if variable is an object
//
// version: 1008.1718
Expand Down Expand Up @@ -1226,10 +1281,11 @@ OWA.util = {
return this.crc32(value);
},

generateRandomGuid : function(salt) {
var time = this.getCurrentUnixTimestamp();
var random = this.rand();
return this.generateHash(time + random + salt);
generateRandomGuid : function() {
var time = this.getCurrentUnixTimestamp() + '';
var random = OWA.util.zeroFill( this.rand(0,999999) + '' , 6);
var client = OWA.util.zeroFill( this.rand(0,999) + '', 3);
return time + random + client;
},

crc32 : function ( str ) {
Expand Down
9 changes: 6 additions & 3 deletions modules/base/js/owa.tracker-combined-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion owa_entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,9 @@ function getProperty($name) {

function generateRandomUid($seed = '') {

return crc32($_SERVER['SERVER_ADDR'].$_SERVER['SERVER_NAME'].getmypid().$this->getTableName().microtime().$seed.rand());
return owa_lib::generateRandomUid();

//return crc32($_SERVER['SERVER_ADDR'].$_SERVER['SERVER_NAME'].getmypid().$this->getTableName().microtime().$seed.rand());
}

/**
Expand Down
18 changes: 18 additions & 0 deletions owa_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,24 @@ public static function isIpAddressValid( $ip = '' ) {
return false;
}
}

public static function zeroFill( $number, $char_length ) {

return str_pad( (int) $number, $char_length, "0", STR_PAD_LEFT );
}

public static function generateRandomUid($seed='') {

$time = (string) time();
$random = owa_lib::zeroFill( mt_rand( 0, 999999 ), 6 );
if ( defined('OWA_SERVER_ID') ) {
$server = owa_lib::zeroFill( OWA_SERVER_ID, 3 );
} else {
$server = substr( getmypid(), 0, 3);
}

return $time.$random.$server;
}
}

?>

0 comments on commit 7e84dbd

Please sign in to comment.