forked from GNUsocial/gnu-social
add groups and joins to createsim.php
This commit is contained in:
parent
7a56637baa
commit
3e293363f6
@ -20,8 +20,8 @@
|
|||||||
|
|
||||||
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
|
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
|
||||||
|
|
||||||
$shortoptions = 'u:n:b:t:x:';
|
$shortoptions = 'u:n:b:g:j:t:x:z:';
|
||||||
$longoptions = array('users=', 'notices=', 'subscriptions=', 'tags=', 'prefix=');
|
$longoptions = array('users=', 'notices=', 'subscriptions=', 'groups=', 'joins=', 'tags=', 'prefix=');
|
||||||
|
|
||||||
$helptext = <<<END_OF_CREATESIM_HELP
|
$helptext = <<<END_OF_CREATESIM_HELP
|
||||||
Creates a lot of test users and notices to (loosely) simulate a real server.
|
Creates a lot of test users and notices to (loosely) simulate a real server.
|
||||||
@ -29,6 +29,8 @@ Creates a lot of test users and notices to (loosely) simulate a real server.
|
|||||||
-u --users Number of users (default 100)
|
-u --users Number of users (default 100)
|
||||||
-n --notices Average notices per user (default 100)
|
-n --notices Average notices per user (default 100)
|
||||||
-b --subscriptions Average subscriptions per user (default no. users/20)
|
-b --subscriptions Average subscriptions per user (default no. users/20)
|
||||||
|
-g --groups Number of groups (default 20)
|
||||||
|
-j --joins Number of groups per user (default 5)
|
||||||
-t --tags Number of distinct hash tags (default 10000)
|
-t --tags Number of distinct hash tags (default 10000)
|
||||||
-x --prefix User name prefix (default 'testuser')
|
-x --prefix User name prefix (default 'testuser')
|
||||||
|
|
||||||
@ -49,6 +51,18 @@ function newUser($i)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function newGroup($i)
|
||||||
|
{
|
||||||
|
global $groupprefix;
|
||||||
|
|
||||||
|
$user = User_group::register(array('nickname' => sprintf('%s%d', $groupprefix, $i),
|
||||||
|
'local' => true,
|
||||||
|
'fullname' => sprintf('Test Group %d', $i)));
|
||||||
|
if (!empty($user)) {
|
||||||
|
$user->free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function newNotice($i, $tagmax)
|
function newNotice($i, $tagmax)
|
||||||
{
|
{
|
||||||
global $userprefix;
|
global $userprefix;
|
||||||
@ -117,38 +131,89 @@ function newSub($i)
|
|||||||
$to->free();
|
$to->free();
|
||||||
}
|
}
|
||||||
|
|
||||||
function main($usercount, $noticeavg, $subsavg, $tagmax)
|
function newJoin($u, $g)
|
||||||
|
{
|
||||||
|
global $userprefix;
|
||||||
|
global $groupprefix;
|
||||||
|
|
||||||
|
$userNumber = rand(0, $u - 1);
|
||||||
|
|
||||||
|
$userNick = sprintf('%s%d', $userprefix, $userNumber);
|
||||||
|
|
||||||
|
$user = User::staticGet('nickname', $userNick);
|
||||||
|
|
||||||
|
if (empty($user)) {
|
||||||
|
throw new Exception("Can't find user '$fromnick'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$groupNumber = rand(0, $g - 1);
|
||||||
|
|
||||||
|
$groupNick = sprintf('%s%d', $groupprefix, $groupNumber);
|
||||||
|
|
||||||
|
$group = User_group::staticGet('nickname', $groupNick);
|
||||||
|
|
||||||
|
if (empty($group)) {
|
||||||
|
throw new Exception("Can't find group '$groupNick'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$user->isMember($group)) {
|
||||||
|
$user->joinGroup($group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
$config['site']['dupelimit'] = -1;
|
$config['site']['dupelimit'] = -1;
|
||||||
|
|
||||||
$n = 1;
|
$n = 1;
|
||||||
|
$g = 1;
|
||||||
|
|
||||||
newUser(0);
|
newUser(0);
|
||||||
|
newGroup(0);
|
||||||
|
|
||||||
// # registrations + # notices + # subs
|
// # registrations + # notices + # subs
|
||||||
|
|
||||||
$events = $usercount + ($usercount * ($noticeavg + $subsavg));
|
$events = $usercount + $groupcount + ($usercount * ($noticeavg + $subsavg + $joinsavg));
|
||||||
|
|
||||||
|
$ut = $usercount;
|
||||||
|
$gt = $ut + $groupcount;
|
||||||
|
$nt = $gt + ($usercount * $noticeavg);
|
||||||
|
$st = $nt + ($usercount * $subsavg);
|
||||||
|
$jt = $st + ($usercount * $joinsavg);
|
||||||
|
|
||||||
for ($i = 0; $i < $events; $i++)
|
for ($i = 0; $i < $events; $i++)
|
||||||
{
|
{
|
||||||
$e = rand(0, 1 + $noticeavg + $subsavg);
|
$e = rand(0, $events);
|
||||||
|
|
||||||
if ($e == 0) {
|
if ($e > 0 && $e <= $ut) {
|
||||||
|
printfv("Creating user $n\n");
|
||||||
newUser($n);
|
newUser($n);
|
||||||
$n++;
|
$n++;
|
||||||
} else if ($e < $noticeavg + 1) {
|
} else if ($e > $ut && $e <= $gt) {
|
||||||
|
printfv("Creating group $g\n");
|
||||||
|
newGroup($g);
|
||||||
|
$g++;
|
||||||
|
} else if ($e > $gt && $e <= $nt) {
|
||||||
|
printfv("Making a new notice\n");
|
||||||
newNotice($n, $tagmax);
|
newNotice($n, $tagmax);
|
||||||
} else {
|
} else if ($e > $nt && $e <= $st) {
|
||||||
|
printfv("Making a new subscription\n");
|
||||||
newSub($n);
|
newSub($n);
|
||||||
|
} else if ($e > $st && $e <= $jt) {
|
||||||
|
printfv("Making a new group join\n");
|
||||||
|
newJoin($n, $g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$usercount = (have_option('u', 'users')) ? get_option_value('u', 'users') : 100;
|
$usercount = (have_option('u', 'users')) ? get_option_value('u', 'users') : 100;
|
||||||
$noticeavg = (have_option('n', 'notices')) ? get_option_value('n', 'notices') : 100;
|
$groupcount = (have_option('g', 'groups')) ? get_option_value('g', 'groups') : 20;
|
||||||
$subsavg = (have_option('b', 'subscriptions')) ? get_option_value('b', 'subscriptions') : max($usercount/20, 10);
|
$noticeavg = (have_option('n', 'notices')) ? get_option_value('n', 'notices') : 100;
|
||||||
$tagmax = (have_option('t', 'tags')) ? get_option_value('t', 'tags') : 10000;
|
$subsavg = (have_option('b', 'subscriptions')) ? get_option_value('b', 'subscriptions') : max($usercount/20, 10);
|
||||||
$userprefix = (have_option('x', 'prefix')) ? get_option_value('x', 'prefix') : 'testuser';
|
$joinsavg = (have_option('j', 'joins')) ? get_option_value('j', 'joins') : 5;
|
||||||
|
$tagmax = (have_option('t', 'tags')) ? get_option_value('t', 'tags') : 10000;
|
||||||
|
$userprefix = (have_option('x', 'prefix')) ? get_option_value('x', 'prefix') : 'testuser';
|
||||||
|
$groupprefix = (have_option('z', 'groupprefix')) ? get_option_value('z', 'groupprefix') : 'testgroup';
|
||||||
|
|
||||||
main($usercount, $noticeavg, $subsavg, $tagmax);
|
main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax);
|
||||||
|
Loading…
Reference in New Issue
Block a user