Make WordPress Core

Opened 20 years ago

Closed 20 years ago

#1159 closed defect (bug) (fixed)

RSS/Atom feeds query too many or too few posts from database when posts to show in HTML templates are denominated in days

Reported by: anonymousbugger's profile anonymousbugger Owned by: ryan's profile ryan
Milestone: Priority: normal
Severity: minor Version: 1.5.1
Component: Template Keywords:
Focuses: Cc:

Description

Let's say that in WordPress 1.5 or 1.5.1, under Options / Reading / Blog Pages, you give WordPress a value denominated in days (show posts from the past 3 days, say).

Let's also say that under Options / Reading / Syndication Feeds, you tell WordPress to include the most recent 25 posts in the Atom and RSS feeds.

WordPress will now query the wrong number of posts from the database when it calls WP_Query::get_posts to retrieve them. Specifically, instead of querying the past 25 *posts* when a feed is requested, it will query the past 25 *days' worth* of posts. If you run a blog where there is more than one post per day, this will waste memory on more posts than are needed (possibly quite a few more, depending on how many posts you get per day). I imagine that if you run a blog where there is less than one post per day this will result in your feeds having *fewer* posts than you told WordPress to put in them--although I haven't verified that.

In any case, I noticed this because it causes a *big* problem if you have a site where there are a large number of posts per day--on our installation at <http://www.feministblogs.org/> this bug was causing PHP to segfault as it tried to read the past 25 days' worth of posts--somewhere around 600 posts or so--and causing PHP to exhaust its memory and segfault whenever anyone requested our newsfeed.

I tracked down the problem and patched it. It's in wp-includes/classes.php, in WP_Query::get_posts. Specifically, it's here:

# --- cut here ---
if ( $this->is_feed )

$qposts_per_page? = get_settings('posts_per_rss');

...

if (($qwhat_to_show? == 'posts')) {

$pgstrt = ;
$pgstrt = (intval($page) -1) * $qposts_per_page? . ', ';
$limits = 'LIMIT '.$pgstrt.$qposts_per_page?;

} elseif ($qwhat_to_show? == 'days') {

...

# --- cut here ---

get_posts() changes posts_per_page to the value of posts_per_rss if a feed is being requested. But it *doesn't* change what_to_show to 'posts', so if you've denominated the Blog Pages number to show in 'days', then get_posts uses that value whether you're requesting Blog Pages or a feed.

It's simple enough to fix of course: just change the first conditional to:

# --- cut here ---
if ( $this->is_feed ) {

$qposts_per_page? = get_settings('posts_per_rss');
$qwhat_to_show? = 'posts';

}
# --- cut here ---

I've patched my installation of WordPress to do this and it seems to have solved the bug.

Change History (2)

#1 @anonymousbugger
20 years ago

  • Patch set to No

#2 @ryan
20 years ago

  • fixed_in_version set to 1.5.1
  • Owner changed from anonymous to rboren
  • Resolution changed from 10 to 20
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.