Changeset 1827


Ignore:
Timestamp:
02/12/10 06:12:22 (5 years ago)
Author:
lowjoel
Message:

OK, this algorithm better work - get the number of unsuperseded builds, get those which should already be superseded, then mark them so.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/website/scripts/downloads.php

    r1814 r1827  
    279279        mysql_query('START TRANSACTION'); 
    280280         
    281         //Get the latest 3 builds and concatenate them into a MySQL set. 
    282         $builds = array(); 
     281        //Get the number of unsuperseded builds for the branch. 
     282        $query = mysql_query(sprintf('SELECT COUNT(builds.DownloadID) FROM builds 
     283            INNER JOIN downloads ON builds.DownloadID=downloads.DownloadID 
     284            WHERE Branch=\'%s\' AND Superseded=0', mysql_real_escape_string($branch))); 
     285        $row = mysql_fetch_row($query); 
     286        $builds = intval($row[0]); 
     287         
     288        //Get the builds which we need to mark superseded 
    283289        $query = mysql_query(sprintf('SELECT builds.DownloadID FROM builds 
    284290            INNER JOIN downloads ON builds.DownloadID=downloads.DownloadID 
    285291            WHERE Branch=\'%s\' AND Superseded=0 
    286             ORDER BY builds.DownloadID DESC LIMIT 3', mysql_real_escape_string($branch))); 
    287         while (($row == mysql_fetch_array($query)) !== false) 
     292            ORDER BY Version ASC 
     293            LIMIT %d', 
     294            mysql_real_escape_string($branch), $builds - 3)); 
     295        $builds = array(); 
     296        while (($row = mysql_fetch_array($query)) !== false) 
    288297            $builds[] = intval($row['DownloadID']); 
    289         $ignoredBuilds = implode(', ', $builds); 
    290          
    291         //Find the builds which need resetting. 
    292         $query = mysql_query(sprintf('SELECT downloads.DownloadID FROM builds 
    293             INNER JOIN downloads ON downloads.DownloadID=builds.DownloadID 
    294             WHERE Branch=\'%s\' AND 
    295             Superseded=0 AND 
    296             downloads.DownloadID NOT IN (%s)', 
    297             mysql_real_escape_string($branch), $ignoredBuilds)); 
    298         $builds = array(); 
    299         while (($row == mysql_fetch_array($query)) !== false) 
    300             $builds[] = intval($row['DownloadID']); 
    301         $ignoredBuilds = implode(', ', $builds); 
    302          
     298        $builds = implode(', ', $builds); 
     299     
    303300        //Set the builds which aren't yet superseded and not in the latest 3 builds 
    304301        //as superseded. 
    305         mysql_query(sprintf('UPDATE downloads SET Superseded=1 
    306             WHERE DownloadID IN (%s)', $ignoredBuilds)); 
     302        mysql_query(sprintf('UPDATE downloads 
     303            SET Superseded=1 WHERE DownloadID IN (%s)', $builds)); 
    307304        mysql_query('COMMIT'); 
    308305        return $buildId; 
Note: See TracChangeset for help on using the changeset viewer.