Skip to content

Commit

Permalink
Fixed ExpireOldBuildsCommand name to RemoveOldBuildsCommand. PR #314.
Browse files Browse the repository at this point in the history
  • Loading branch information
corpsee committed May 3, 2020
1 parent 342bef7 commit 19503d9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/en/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Console commands
* `php-censor:check-localizations` - Check localizations.
* `php-censor:create-admin` - Create an admin user.
* `php-censor:create-build` - Create a build for a project.
* `php-censor:expire-old-builds` - Clean up old builds.
* `php-censor:remove-old-builds` - Clean up old builds.
* `php-censor:install` - Install PHP Censor.
* `php-censor:rebuild` - Re-runs the last run build.
* `php-censor:rebuild-queue` - Rebuilds the PHP Censor worker queue.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
* Expire old builds.
* Remove old builds
*
* @author David Sloan <dave@d3r.com>
*/
class ExpireOldBuildsCommand extends Command
class RemoveOldBuildsCommand extends Command
{
/**
* @var ProjectStore
Expand Down Expand Up @@ -47,8 +47,8 @@ public function __construct(ProjectStore $projectStore, BuildService $buildServi
protected function configure()
{
$this
->setName('php-censor:expire-old-builds')
->setDescription('Expires Old Builds.');
->setName('php-censor:remove-old-builds')
->setDescription('Remove old builds.');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use PHPCensor\Command\CreateAdminCommand;
use PHPCensor\Command\CreateBuildCommand;
use PHPCensor\Command\InstallCommand;
use PHPCensor\Command\ExpireOldBuildsCommand;
use PHPCensor\Command\RemoveOldBuildsCommand;
use PHPCensor\Command\RebuildCommand;
use PHPCensor\Command\RebuildQueueCommand;
use PHPCensor\Command\RunCommand;
Expand Down Expand Up @@ -173,7 +173,7 @@ public function __construct($name = 'PHP Censor', $version = 'UNKNOWN')
$this->add(new InstallCommand());
$this->add(new CreateAdminCommand($userStore));
$this->add(new CreateBuildCommand($projectStore, $buildService));
$this->add(new ExpireOldBuildsCommand($projectStore, $buildService));
$this->add(new RemoveOldBuildsCommand($projectStore, $buildService));
$this->add(new WorkerCommand($logger, $buildService));
$this->add(new RunCommand($logger, $buildService));
$this->add(new RebuildQueueCommand($logger));
Expand Down
3 changes: 1 addition & 2 deletions src/Service/BuildService.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ public function createDuplicateBuild(Build $originalBuild, $source)
public function deleteOldByProject($projectId)
{
$keepBuilds = (int)Config::getInstance()->get('php-censor.build.keep_builds', 100);
$keepBatch = (int)Config::getInstance()->get('php-censor.build.keep_builds_batchsize', 100);
$builds = $this->buildStore->getOldByProject((int)$projectId, $keepBuilds, $keepBatch);
$builds = $this->buildStore->getOldByProject((int)$projectId, $keepBuilds);

/** @var Build $build */
foreach ($builds['items'] as $build) {
Expand Down
23 changes: 8 additions & 15 deletions src/Store/BuildStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,29 +518,22 @@ public function deleteAllByProject($projectId)
}

/**
* Get old Builds by project.
* - Get a batch of projects past the keep threshold.
* - Reasonable batch size of 100.
* @param int $projectId
* @param int $keep
*
* @param int $projectId
* @param int $keep
* @param int $batchSize
* @return array
*
* @throws HttpException
*/
public function getOldByProject($projectId, $keep = 100, $batchSize = 100)
public function getOldByProject($projectId, $keep = 100)
{
if (is_null($projectId)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}

$query = 'SELECT * FROM {{' . $this->tableName . '}} ' .
'WHERE {{project_id}} = :project_id ' .
'ORDER BY {{create_date}} DESC ' .
'LIMIT :batch_size OFFSET :keep';

$query = 'SELECT * FROM {{' . $this->tableName . '}} WHERE {{project_id}} = :project_id ORDER BY {{create_date}} DESC LIMIT 1000000 OFFSET :keep';
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':project_id', $projectId);
$stmt->bindValue(':batch_size', (int)$batchSize, PDO::PARAM_INT);
$stmt->bindValue(':keep', (int)$keep, PDO::PARAM_INT);

if ($stmt->execute()) {
Expand Down Expand Up @@ -635,8 +628,8 @@ public function getBuildErrorsTrend($buildId, $projectId, $branch)

if ($stmt->execute()) {
return $stmt->fetchAll(PDO::FETCH_ASSOC);
} else {
return [];
}

return [];
}
}

0 comments on commit 19503d9

Please sign in to comment.