]> git.mjollnir.org Git - s9y.git/commitdiff
Improve SQL query for fetching archive overview, from $year*$month queries to 1. :-)
authorgarvinhicking <garvinhicking>
Tue, 27 Feb 2007 11:20:47 +0000 (11:20 +0000)
committergarvinhicking <garvinhicking>
Tue, 27 Feb 2007 11:20:47 +0000 (11:20 +0000)
docs/NEWS
include/functions_entries.inc.php

index 3f2167d1556e6f9f01e3e7489bbc7a9111335f31..5ea66f4e4e7b7bdf70935fff15311f731d271905 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,10 @@
 Version 1.2 ()
 ------------------------------------------------------------------------
 
+    * Improve performance of displaying the complete archive. Instead
+      of year*months SQL queries, only one query is now used.
+      (garvinhicking)
     * Improve installation on hosts where fsockopen() is disabled
       (garvinhicking)
       
index 374729564722edda7e14c88f8b830b708ee18138..2a75027b54f6ce9df3be69bda159ae7e3cc19592 100644 (file)
@@ -1457,6 +1457,25 @@ function serendipity_printArchives() {
         $author_get = '';
     }
 
+    $q = "SELECT e.timestamp
+            FROM {$serendipity['dbPrefix']}entries e
+            " . (!empty($cat_sql) ? "
+       LEFT JOIN {$serendipity['dbPrefix']}entrycat ec
+              ON e.id = ec.entryid
+       LEFT JOIN {$serendipity['dbPrefix']}category c
+              ON ec.categoryid = c.categoryid" : "") . "
+           WHERE isdraft = 'false'"
+                . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND timestamp <= " . serendipity_db_time() : '')
+                . (!empty($cat_sql) ? ' AND ' . $cat_sql : '')
+                . (!empty($serendipity['GET']['viewAuthor']) ? ' AND e.authorid = ' . (int)$serendipity['GET']['viewAuthor'] : '') 
+                . (!empty($cat_sql) ? " GROUP BY e.id" : '');
+    $entries =& serendipity_db_query($q, false, 'assoc');
+
+    $group = array();
+    foreach($entries AS $entry) {
+        $group[date('Ym', $entry['timestamp'])]++;
+    }
+
     $output = array();
     for ($y = $thisYear; $y >= $lastYear; $y--) {
         $output[$y]['year'] = $y;
@@ -1485,24 +1504,7 @@ function serendipity_printArchives() {
                     break;
             }
 
-            $entries =& serendipity_db_query("SELECT count(id)
-                                               FROM {$serendipity['dbPrefix']}entries e
-                                          LEFT JOIN {$serendipity['dbPrefix']}entrycat ec
-                                                 ON e.id = ec.entryid
-                                          LEFT JOIN {$serendipity['dbPrefix']}category c
-                                                 ON ec.categoryid = c.categoryid
-                                              WHERE isdraft = 'false'
-                                                AND timestamp >= $s
-                                                AND timestamp <= $e "
-                                                    . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND timestamp <= " . serendipity_db_time() : '')
-                                                    . (!empty($cat_sql) ? ' AND ' . $cat_sql : '')
-                                                    . (!empty($serendipity['GET']['viewAuthor']) ? ' AND e.authorid = ' . (int)$serendipity['GET']['viewAuthor'] : '') . "
-                                           GROUP BY ec.entryid", false, 'assoc');
-            if (is_array($entries)) {
-                $entry_count = count($entries);
-            } else {
-                $entry_count = 0;
-            }
+            $entry_count = (int)$group[$y . (strlen($m) == 1 ? '0' : '') . $m];
 
             /* A silly hack to get the maximum amount of entries per month */
             if ($entry_count > $max) {