Changeset 166 for trunk/service.php


Ignore:
Timestamp:
12/18/07 20:06:45 (5 years ago)
Author:
Lantash
Message:

Performance optimization in the web service method gallery_getalbums: Only perform one database query to obtain the number of pictures in each album.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/service.php

    r164 r166  
    658658    $database = Core::getDatabase(); 
    659659         
    660         $database->setQuery("SELECT * FROM #__gallery_albums"); 
     660        $database->setQuery("SELECT a.*, COUNT(p.albumid) AS pictures FROM #__gallery_albums AS a LEFT JOIN #__gallery_pictures AS p ON a.id = p.albumid GROUP BY a.id"); 
    661661        $albumsResponse = $database->loadAssocList(); 
    662662         
     
    668668     
    669669        foreach ($albumsResponse as $album) { 
    670                 // Needs optimization 
    671                 $database->setQuery("SELECT * FROM #__gallery_pictures WHERE albumid = " . (int) $album["id"]); 
    672                  
    673670        $albums[] = Array( 
    674671            "id"          => (int)    $album["id"], 
    675672            "name"        => (string) $album["name"], 
    676673            "description" => (string) $album["description"], 
    677             "pictures"    => (int)        $database->getNumRows($database->query()) 
     674            "pictures"    => (int)        $album["pictures"] 
    678675                ); 
    679676        } 
Note: See TracChangeset for help on using the changeset viewer.