From 91d8a28c664afa5378735bcd0efe068dd74d589f Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sun, 1 Apr 2018 19:16:13 +0200 Subject: Use method "buildByAttribute" to create Item instances for item listing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit significantly reduces the number of database queries required to display a list of pages, posts or users. This could be achieved by using "SELECT * FROM […]" in combination with the new implemented factory method "buildByAttribute". Previously, the first database query returned an array of unique item IDs that were then passed to the factory method "build" within the "foreach" loop which caused the application to make an additional database query like "SELECT * FROM […] WHERE id = {current_id}" for every single item ID to get it's payload data. Since this commit, this additional query for every item is not necessary anymore. --- admin/page/index.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'admin/page/index.php') diff --git a/admin/page/index.php b/admin/page/index.php index c14bf13..caff257 100644 --- a/admin/page/index.php +++ b/admin/page/index.php @@ -26,18 +26,18 @@ if($currentSite < 1 OR ($currentSite > $lastSite AND $lastSite > 0)) { } #=============================================================================== -# Fetch page IDs from database +# Fetch items from database #=============================================================================== -$execSQL = "SELECT id FROM %s ORDER BY {$site_sort} LIMIT ".(($currentSite-1) * $site_size).", {$site_size}"; -$pageIDs = $Database->query(sprintf($execSQL, Page\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN); +$execSQL = "SELECT * FROM %s ORDER BY {$site_sort} LIMIT ".(($currentSite-1) * $site_size).", {$site_size}"; +$Statement = $Database->query(sprintf($execSQL, Page\Attribute::TABLE)); #=============================================================================== # TRY: Template\Exception #=============================================================================== try { - foreach($pageIDs as $pageID) { + while($Attribute = $Statement->fetchObject('Page\Attribute')) { try { - $Page = Page\Factory::build($pageID); + $Page = Page\Factory::buildByAttribute($Attribute); $User = User\Factory::build($Page->attr('user')); $ItemTemplate = generatePageItemTemplate($Page, $User); -- cgit v1.2.3