Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22551
Modified Files:
serendipity_functions.inc.php
serendipity_admin_entries.inc.php
Log Message:
Needed to revert previous code for fetching categories and do one additional
query instead, because of Bug #971652.
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.287
retrieving revision 1.288
diff -u -d -r1.287 -r1.288
--- serendipity_functions.inc.php 11 Jun 2004 12:50:50 -0000 1.287
+++ serendipity_functions.inc.php 14 Jun 2004 11:41:39 -0000 1.288
@@ -714,13 +714,7 @@
e.last_modified,
a.username,
- a.email,
-
- c.categoryid,
- c.category_name,
- c.category_description,
- c.category_icon,
- c.parentid
+ a.email
$body
FROM
@@ -731,6 +725,8 @@
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";
@@ -742,48 +738,40 @@
}
if (is_array($ret)) {
- // 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
+ // The article's query LIMIT operates on a flattened entries layer so that
+ // an article having 5 associated categories won't count as 5 entries.
+ // But to store the expanded list of categories, we need to send a new
+ // query once for all entries we have just fetched.
+ // First code for this was sending 15 queries for 15 fetched entries,
+ // this is now limited to just one query per fetched articles group
- foreach ($ret as $_id => $entry) {
+ $search_ids = array(); // An array to hold all ids of the entry we want to fetch.
+ $assoc_ids = array(); // A temporary key association container to not have to loop through the return array once again.
- 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'] = array();
- }
+ foreach($ret AS $i => $entry) {
+ $search_ids[] = $entry['id'];
+ $ret[$i]['categories'] = array(); // make sure every article gets its category association
+ $assoc_ids[$entry['id']] = $i; // store temporary reference
+ }
- $i++;
- $return[$i] = $entry;
- $seen_id[$entry['id']] = true;
- }
+ $query = "SELECT
+ ec.entryid,
+ c.categoryid,
+ c.category_name,
+ c.category_description,
+ c.category_icon,
+ c.parentid
+ FROM {$serendipity['dbPrefix']}category AS c
+ LEFT JOIN {$serendipity['dbPrefix']}entrycat AS ec
+ ON ec.categoryid = c.categoryid
+ WHERE ec.entryid IN (" . implode(', ', $search_ids) . ")";
- 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']
- );
+ $search_ret = serendipity_db_query($query);
+ if (is_array($search_ret)) {
+ foreach($search_ret AS $i => $entry) {
+ $ret[$assoc_ids[$entry['entryid']]]['categories'][] = $entry;
}
-
- 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'] = array();
- }
-
- return $return;
}
return $ret;
Index: serendipity_admin_entries.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_admin_entries.inc.php,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- serendipity_admin_entries.inc.php 7 Jun 2004 18:38:16 -0000 1.25
+++ serendipity_admin_entries.inc.php 14 Jun 2004 11:41:39 -0000 1.26
@@ -154,7 +154,7 @@
?>
<tr>
<td colspan="<?php echo $halfRowLeft; ?>">
- <input type="submit" name="serendipity[prevpage]" value="<<<" <?php if ($serendipity['GET']['offset'] <= 0) echo ' disabled' ?> />
+ <input type="submit" name="serendipity[prevpage]" value="<<<" <?php if ($serendipity['GET']['offset'] <= 0) echo ' disabled="disabled"' ?> />
</td>
<td class="serendipity_admin_filters" align="center">
@@ -163,7 +163,7 @@
</td>
<td colspan="<?php echo $halfRowRight; ?>" align="right">
- <input type="submit" name="serendipity[nextpage]" value=">>>" <?php if ($count != $perPage) echo ' disabled' ?> />
+ <input type="submit" name="serendipity[nextpage]" value=">>>" <?php if ($count != $perPage) echo ' disabled="disabled"'; ?> />
</td>
</tr>
</table>
@@ -363,4 +363,4 @@
);
}
/* vim: set sts=4 ts=4 expandtab : */
-?>
+?>
\ No newline at end of file
|