Posted on — Last updated on October 11, 2019

WordPress Popular Posts 4.2 is all about speed!

This release focuses heavily on performance: improved database queries & persistent object caching support! (+ goodies!)

Database queries have been tweaked for performance and persistent object caching support has been included as well. This release is -at least- 50% faster than any of its predecessors!

Performance has always been a hot topic, especially in web development where speed is crucial not only for a good user experience but even for SEO as well.

Faster, more efficient database queries

One of the greatest strengths of FOSS lies in its collaborative nature: virtually anyone can review your code and make suggestions on how to improve it.

A member of the community was kind enough to propose a few changes to help improve WPP’s database query response times.

After a few message exchanges and some tests, I was able to confirm that the aforementioned modifications made queries noticeable faster: on my setup, retrieving the most viewed posts with comments from the database took around 0.07215 seconds with the original query, while the final modified one averaged 0.01388 seconds. That’s 80.76% faster! (Your mileage may vary of course, but still!)

In layman’s terms, what this all means is that the plugin can read data from your database significantly faster, using less resources. A big plus for perfomance!

Also, and while it might be obvious, this also means that the database queries built by the WPP_Query class were partially rewritten so if you happen to be a developer and you hooked into it to customize the queries -as I’m sure some of you did- there’s a pretty big chance that this change will break your custom query so please review and update your code before upgrading to version 4.2.

Pageviews Caching

Improving the database queries was a big step towards making WordPress Popular Posts faster and less resource intensive, but it wasn’t the only one.

As you’re probably already aware of, WordPress Popular Posts keeps track of every visit your site gets, saving every page view into your database. That’s how the plugin can rank your popular posts by views count. This is fine and dandy but it has a drawback: if you have a high traffic site this also means that WPP will be writing to the database very often which can affect its performance during peak traffic hours.

To mitigate this issue, WordPress Popular Posts 3.2 introduced Data Sampling, a feature that allows the plugin to track only subset of your traffic and report on the tendencies detected in that sample set. By doing this, the plugin reduces the number of database writes by a fraction which in turn helps performance. This was, until now, the go-to solution for high traffic sites using WordPress Popular Posts.

Starting version 4.2, WordPress Popular Posts also introduces the ability to temporarily store views count data in a persistent object cache (eg. Redis, Memcached, etc) before saving it to the database. This reduces tremendously database write operations which is great for performance – especially for large/high traffic sites. This is now the preferred solution as it scales better and also eliminates the need to track only a subset of the traffic. If your hosting provider offers support for Redis, Memcached, APC, etc. then this is for you.

For more details, check the documentation.

New filter hook: wpp_parse_custom_content_tags

Up until version 4.1.x, WordPress Popular Posts includes 17 Content Tags that people can use to customize the HTML output of the plugin.

Custom HTML markup with Content Tags
Custom HTML markup with Content Tags

For most cases that’s enough, but there have been some instances were users needed to display additional data (eg. a value from a custom field, or a custom taxonomy) and couldn’t do so via the Custom HTML Markup feature provided by the widget because they could only use the existing content tags. Adding new features usually meant having to use WPP’s filter hooks, even if if was just to include one simple thing.

From version 4.2 and on, you can hook into wpp_parse_custom_content_tags to parse your custom content tags (like the {tags} one from the image above). Check the documentation for more!

New filter hook: wpp_taxonomy_separator

By default, WordPress Popular Posts uses the comma character to separate a list of taxonomy items (categories, tags, etcetera). From time to time, people at the support forums show up to ask the same question: “How can I split my categories by [insert desired character here] instead of commas?”

For all of you people out there: wpp_taxonomy_separator!

A few days back, I published an utility plugin that adds a RSS feed of popular posts to WordPress.

It doesn’t come with a Settings menu but there’s a filter hook you can use to customize the feed a bit if you need to. Check out WordPress Popular Posts Feed for more.

Other changes

Naturally, all of the above weren’t the only changes included with this release. Version 4.2 brings a few minor fixes and improvements as well, head to the WordPress Popular Posts’ GitHub repo if you want to see what else has changed.

Until next time!