Skip to content

Commit

Permalink
Made it possible to use the cache as an sql dump; minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sanikolaev committed Dec 27, 2024
1 parent 92cb51d commit 1156045
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ private function showUsage($error = null) {
" <int/1/100> Random integer between 1 and 100\n" .
" <float/1/1000> Random float between 1 and 1000\n" .
" <boolean> Random true or false\n" .
" <array/2/10/100/1000> Array of 2-10 elements, values 100-1000\n\n" .
" <array/2/10/100/1000> Array of 2-10 elements, values 100-1000\n" .
" <array_float/256/512/0/1> Array of 256-512 random floats, values between 0 and 1\n\n" .

"Examples:\n\n" .
"# Load 1M documents in batches of 1000:\n" .
Expand Down
9 changes: 5 additions & 4 deletions src/query_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,19 +435,19 @@ private function generateAndCacheQueries($quiet) {

if (count($batch) == $batch_size) {
$full_query = $base_query . implode(",", $batch);
fwrite($cache_file, $full_query . "\n");
fwrite($cache_file, $full_query . ";\n");
$queries[] = $full_query;
$batch = [];
}
} else {
fwrite($cache_file, $query . "\n");
fwrite($cache_file, $query . ";\n");
$queries[] = $query;
}

$c++;
if ($c % 1000 == 0 && !$quiet) {
$progress = sprintf("\r%-80s\r", "");
$progress .= sprintf("Process {$this->process_index}: Generating new data cache... %d%%",
$progress .= sprintf("Process {$this->process_index}: Generating new data cache {$this->cache_file_name} ... %d%%",
round($c * 100 / $this->config->get('total'))
);
ConsoleOutput::write($progress);
Expand All @@ -463,7 +463,7 @@ private function generateAndCacheQueries($quiet) {
fclose($cache_file);
if (!$quiet) {
ConsoleOutput::write(sprintf("\r%-80s\r", ""));
ConsoleOutput::writeLine(sprintf("Process {$this->process_index}: Generating new data cache... 100%%"));
ConsoleOutput::writeLine(sprintf("Process {$this->process_index}: Generating new data cache {$this->cache_file_name} ... 100%%"));
}

return $queries;
Expand All @@ -479,6 +479,7 @@ private function generateSingleQuery() {
$value = $this->generateValue($pattern);
$query = str_replace("<$pattern_text>", $value, $query);
}
rtrim($query, ';');
return $query;
}

Expand Down

0 comments on commit 1156045

Please sign in to comment.