]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/createsim.php
Merge branch '1.0.x' into prefillbookmark
[quix0rs-gnu-social.git] / scripts / createsim.php
index 3244cda104708dae8e897e8c09425136ab624abb..7435dcfeb28a89bd780d7fc7020ce0e89ebe5427 100644 (file)
@@ -33,6 +33,7 @@ Creates a lot of test users and notices to (loosely) simulate a real server.
     -j --joins         Number of groups per user (default 5)
     -t --tags          Number of distinct hash tags (default 10000)
     -x --prefix        User name prefix (default 'testuser')
+    -w --words         Words file (default '/usr/share/dict/words')
 
 END_OF_CREATESIM_HELP;
 
@@ -71,18 +72,18 @@ function newNotice($i, $tagmax)
 {
     global $userprefix;
 
-    $options = array();
+    $options = array('scope' => common_config('notice', 'defaultscope'));
 
     $n = rand(0, $i - 1);
     $user = User::staticGet('nickname', sprintf('%s%d', $userprefix, $n));
 
     $is_reply = rand(0, 1);
 
-    $content = 'Test notice content';
+    $content = testNoticeContent();
 
     if ($is_reply == 0) {
-        common_set_user($user);
-        $notices = $user->noticesWithFriends(0, 20);
+        $stream = new InboxNoticeStream($user, $user->getProfile());
+        $notices = $stream->getNotices(0, 20);
         if ($notices->N > 0) {
             $nval = rand(0, $notices->N - 1);
             $notices->fetch(); // go to 0th
@@ -95,6 +96,10 @@ function newNotice($i, $tagmax)
                 $rprofile = $notices->getProfile();
                 $content = "@".$rprofile->nickname." ".$content;
             }
+            $private_to_addressees = rand(0, 4);
+            if ($private_to_addressees == 0) {
+                $options['scope'] |= Notice::ADDRESSEE_SCOPE;
+            }
         }
     }
 
@@ -120,9 +125,19 @@ function newNotice($i, $tagmax)
             }
             $options['groups'] = array($groups->id);
             $content = "!".$groups->nickname." ".$content;
+            $private_to_group = rand(0, 2);
+            if ($private_to_group == 0) {
+                $options['scope'] |= Notice::GROUP_SCOPE;
+            }
         }
     }
 
+    $private_to_site = rand(0, 4);
+
+    if ($private_to_site == 0) {
+        $options['scope'] |= Notice::SITE_SCOPE;
+    }
+
     $notice = Notice::saveNew($user->id, $content, 'system', $options);
 }
 
@@ -192,21 +207,64 @@ function newJoin($u, $g)
     }
 }
 
+function testNoticeContent()
+{
+    global $words;
+    
+    if (is_null($words)) {
+        return "test notice content";
+    }
+
+    $cnt = rand(3, 8);
+
+    $ids = array_rand($words, $cnt);
+
+    foreach ($ids as $id) {
+        $parts[] = $words[$id];
+    }
+
+    $text = implode(' ', $parts);
+    
+    if (mb_strlen($text) > 80) {
+        $text = substr($text, 0, 77) . "...";
+    }
+    
+    return $text;
+}
+
 function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax)
 {
     global $config;
     $config['site']['dupelimit'] = -1;
 
-    $n = 1;
-    $g = 1;
+    $n = 0;
+    $g = 0;
+
+    // Make users first
+
+    $preuser = min($usercount, 5);
+
+    for ($j = 0; $j < $preuser; $j++) {
+        printfv("$i Creating user $n\n");
+        newUser($n);
+        $n++;
+    }
+
+    $pregroup = min($groupcount, 3);
 
-    newUser(0);
-    newGroup(0, $n);
+    for ($k = 0; $k < $pregroup; $k++) {
+        printfv("$i Creating group $g\n");
+        newGroup($g, $n);
+        $g++;
+    }
 
     // # registrations + # notices + # subs
 
     $events = $usercount + $groupcount + ($usercount * ($noticeavg + $subsavg + $joinsavg));
 
+    $events -= $preuser;
+    $events -= $pregroup;
+
     $ut = $usercount;
     $gt = $ut + $groupcount;
     $nt = $gt + ($usercount * $noticeavg);
@@ -250,6 +308,13 @@ $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';
+$wordsfile   = (have_option('w', 'words')) ? get_option_value('w', 'words') : '/usr/share/dict/words';
+
+if (is_readable($wordsfile)) {
+    $words = file($wordsfile);
+} else {
+    $words = null;
+}
 
 try {
     main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax);