Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5304
Modified Files:
serendipity_functions.inc.php
Log Message:
performance increase: do not call serendipity_fetchcategoryinfo once per
entry; once per query is often enougn ;)
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.279
retrieving revision 1.280
diff -u -d -r1.279 -r1.280
--- serendipity_functions.inc.php 7 Jun 2004 14:22:47 -0000 1.279
+++ serendipity_functions.inc.php 7 Jun 2004 15:29:39 -0000 1.280
@@ -714,7 +714,13 @@
e.last_modified,
a.username,
- a.email
+ a.email,
+
+ c.categoryid,
+ c.category_name,
+ c.category_description,
+ c.category_icon,
+ c.parentid
$body
FROM
@@ -725,8 +731,6 @@
ON e.id = ec.entryid
LEFT JOIN {$serendipity['dbPrefix']}category c
ON ec.categoryid = c.categoryid $and
- GROUP BY
- e.id
ORDER BY
$orderby
$limit";
@@ -738,10 +742,50 @@
}
if (is_array($ret)) {
- foreach ($ret as $i => $entry) {
- $ret[$i]['categories'] = $ret[$i][] = serendipity_fetchEntryCategories($entry['id']);
+ // We want to save us a few DB query, so we don't group the above query by ids,
+ // and instead populate an array flattened to entry ids, but with all supplemental
+ // category information.
+
+ $return = array(); // will hold the flattened array
+ $seen_id = array(); // holds information of already seen entries
+ $i = -1; // inremental counter for array-compatibility
+
+ foreach ($ret as $_id => $entry) {
+
+ if (!isset($seen_id[$entry['id']])) {
+ // check whether there were any associated categories.
+ // if not, store a 'True' value for compatibility.
+ if ($i > -1 && !isset($return[$i]['categories'])) {
+ $return[$i]['categories'] = 1;
+ }
+
+ $i++;
+ $return[$i] = $entry;
+ $seen_id[$entry['id']] = true;
+ }
+
+ if (isset($entry['categoryid'])) {
+ // Only append category array if association is present
+ $return[$i]['categories'][] = array(
+ 'categoryid' => $entry['categoryid'],
+ 'category_name' => $entry['category_name'],
+ 'category_description' => $entry['category_description'],
+ 'category_icon' => $entry['category_icon'],
+ 'parentid' => $entry['parentid']
+ );
+ }
+
+ unset($ret[$_id]); // save some memory, we don't need this array element any more :-)
}
+
+ if ($i > -1 && !isset($return[$i]['categories'])) {
+ // see above
+ $return[$i]['categories'] = 1;
+ }
+
+ return $return;
}
+
return $ret;
}
|