Add reply_to to make conversations in createsim.php

This commit is contained in:
Evan Prodromou 2011-03-26 14:58:11 -04:00
parent a5fd9b705a
commit bc2f64d7ab

View File

@ -67,6 +67,8 @@ function newNotice($i, $tagmax)
{ {
global $userprefix; global $userprefix;
$options = array();
$n = rand(0, $i - 1); $n = rand(0, $i - 1);
$user = User::staticGet('nickname', sprintf('%s%d', $userprefix, $n)); $user = User::staticGet('nickname', sprintf('%s%d', $userprefix, $n));
@ -75,8 +77,20 @@ function newNotice($i, $tagmax)
$content = 'Test notice content'; $content = 'Test notice content';
if ($is_reply == 0) { if ($is_reply == 0) {
$n = rand(0, $i - 1); $r = rand(0, max($i - 1, 0));
$content = "@$userprefix$n " . $content; $rnick = sprintf('%s%d', $userprefix, $r);
$ruser = User::staticGet('nickname', $rnick);
common_set_user($user);
$notices = $ruser->getNotices(0, 5);
if ($notices->N > 0) {
$nval = rand(0, $notices->N);
$notices->fetch(); // go to 0th
for ($i = 0; $i < $nval; $i++) {
$notices->fetch();
}
$options['reply_to'] = $notices->id;
}
$content = "@$rnick " . $content;
} }
$has_hash = rand(0, 2); $has_hash = rand(0, 2);
@ -89,10 +103,7 @@ function newNotice($i, $tagmax)
} }
} }
$notice = Notice::saveNew($user->id, $content, 'system'); $notice = Notice::saveNew($user->id, $content, 'system', $options);
$user->free();
$notice->free();
} }
function newSub($i) function newSub($i)
@ -182,27 +193,31 @@ function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax)
$st = $nt + ($usercount * $subsavg); $st = $nt + ($usercount * $subsavg);
$jt = $st + ($usercount * $joinsavg); $jt = $st + ($usercount * $joinsavg);
printfv("$events events ($ut, $gt, $nt, $st, $jt)\n");
for ($i = 0; $i < $events; $i++) for ($i = 0; $i < $events; $i++)
{ {
$e = rand(0, $events); $e = rand(0, $events);
if ($e > 0 && $e <= $ut) { if ($e > 0 && $e <= $ut) {
printfv("Creating user $n\n"); printfv("$i Creating user $n\n");
newUser($n); newUser($n);
$n++; $n++;
} else if ($e > $ut && $e <= $gt) { } else if ($e > $ut && $e <= $gt) {
printfv("Creating group $g\n"); printfv("$i Creating group $g\n");
newGroup($g); newGroup($g);
$g++; $g++;
} else if ($e > $gt && $e <= $nt) { } else if ($e > $gt && $e <= $nt) {
printfv("Making a new notice\n"); printfv("$i Making a new notice\n");
newNotice($n, $tagmax); newNotice($n, $tagmax);
} else if ($e > $nt && $e <= $st) { } else if ($e > $nt && $e <= $st) {
printfv("Making a new subscription\n"); printfv("$i Making a new subscription\n");
newSub($n); newSub($n);
} else if ($e > $st && $e <= $jt) { } else if ($e > $st && $e <= $jt) {
printfv("Making a new group join\n"); printfv("$i Making a new group join\n");
newJoin($n, $g); newJoin($n, $g);
} else {
printfv("No event for $i!");
} }
} }
} }
@ -216,4 +231,8 @@ $tagmax = (have_option('t', 'tags')) ? get_option_value('t', 'tags') : 1000
$userprefix = (have_option('x', 'prefix')) ? get_option_value('x', 'prefix') : 'testuser'; $userprefix = (have_option('x', 'prefix')) ? get_option_value('x', 'prefix') : 'testuser';
$groupprefix = (have_option('z', 'groupprefix')) ? get_option_value('z', 'groupprefix') : 'testgroup'; $groupprefix = (have_option('z', 'groupprefix')) ? get_option_value('z', 'groupprefix') : 'testgroup';
main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax); try {
main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax);
} catch (Exception $e) {
printfv("Got an exception: ".$e->getMessage());
}