Skip to content

Commit

Permalink
Web|Builder: Don’t purge unstable builds if there’s too few available
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 2, 2017
1 parent 792d569 commit edb05c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion webapi/1/admin/bdb.php
Expand Up @@ -108,9 +108,15 @@ function remove_file($db, $file_id)
function purge_old_builds()
{
$expire_ts = time() - 100 * 24 * 60 * 60;

// If there is a small number of recent builds, don't purge at all.
$db = db_open();
if (db_build_count($db, BT_UNSTABLE) <= 5) {
$db->close();
return;
}

// Find non-stable builds that have become obsolete.
$db = db_open();
$result = db_query($db, "SELECT build FROM ".DB_TABLE_BUILDS
." WHERE type != ".BT_STABLE." AND UNIX_TIMESTAMP(timestamp) < $expire_ts");
$builds_sql = "";
Expand Down
7 changes: 7 additions & 0 deletions webapi/1/builds.inc.php
Expand Up @@ -120,6 +120,13 @@ function db_build_binary_count($db, $build)
return $result->num_rows;
}

function db_build_count($db, $type)
{
$result = db_query($db, "SELECT build FROM ".DB_TABLE_BUILDS
." WHERE type=".$type);
return $result->num_rows;
}

function db_build_summary($db, $build)
{
// Fetch build info.
Expand Down

0 comments on commit edb05c7

Please sign in to comment.