Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/cdash/app/Model/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use DateTimeZone;
use Exception;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use PDO;
Expand Down Expand Up @@ -501,6 +502,15 @@ public function CheckForTooManyBuilds(): bool
return false;
}

// Fetching the exact build count is expensive, so don't do it if it's been less than
// 10 minutes since the last time we checked. While this means build counts can temporarily
// be higher than the limit, it lightens the database load during peak hours.
$cache_key = "check_too_many_builds_project_{$this->Id}";
if (Cache::has($cache_key)) {
return false;
}
Cache::put($cache_key, true, 10 * 60);

$project = EloquentProject::findOrFail((int) $this->Id);
$num_builds = $project->builds()->onlyParents()->count();

Expand Down
12 changes: 10 additions & 2 deletions app/cdash/tests/test_limitedbuilds.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use CDash\Database;
use CDash\Model\Build;
use CDash\Model\Project;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class LimitedBuildsTestCase extends KWWebTestCase
Expand Down Expand Up @@ -58,14 +59,21 @@ public function testLimitedBuilds(): void

$project = App\Models\Project::findOrFail((int) $this->Projects[0]->Id);

// Submit two builds to the 'Limited' project.
// The second submission will cause the first build to get deleted.
// Submit three builds to the 'Limited' project.
// The second submission will not cause the first build to get deleted because it's been
// than 10 minutes since the previous build. Flushing the cache expires the record and
// means submitting the 3rd build will cause the first two to be deleted.
$this->submitBuild(1, 'Limited');
$this->assertEqual($project->refresh()->builds()->count(), 1);

$this->get_build_stmt->execute([$this->Projects[0]->Id]);
$buildid1 = $this->get_build_stmt->fetchColumn();

$this->submitBuild(2, 'Limited');
$this->assertEqual($project->refresh()->builds()->count(), 2);

Cache::flush();

$this->submitBuild(2, 'Limited');
$this->assertEqual($project->refresh()->builds()->count(), 1);

Expand Down
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9219,6 +9219,12 @@ parameters:
count: 1
path: app/cdash/app/Model/Project.php

-
rawMessage: 'Method CDash\Model\Project::CheckForTooManyBuilds() throws checked exception Psr\SimpleCache\InvalidArgumentException but it''s missing from the PHPDoc @throws tag.'
identifier: missingType.checkedException
count: 1
path: app/cdash/app/Model/Project.php

-
rawMessage: 'Method CDash\Model\Project::ComputeTestingDayBounds() has parameter $date with no type specified.'
identifier: missingType.parameter
Expand Down