cabrerahector / wordpress-popular-posts

WordPress Popular Posts - A highly customizable WordPress widget that displays your most popular posts.
https://wordpress.org/plugins/wordpress-popular-posts/
GNU General Public License v2.0
280 stars 82 forks source link

Missing Performance Feature from Wiki #326

Closed pacifier007 closed 2 years ago

pacifier007 commented 2 years ago

There's a featured mentioned in the performance section of wiki to batch update object cache instead of logging views right away.

https://github.com/cabrerahector/wordpress-popular-posts/wiki/7.-Performance#caching

I tried it but it doesn't work. Looks like there's no code for it. In Front.php I see there is no code to batch update, it updates right away.

Am I missing something or this feature not done yet (will release in future update?)

cabrerahector commented 2 years ago

Hi @pacifier007,

That "batch update" feature refers to the Pageviews Cache :)

From the documentation:

Starting version 4.2.0 WordPress Popular Posts can cache views data in-memory (Redis, Memcached, etcetera) and batch update the views count of your posts & pages when more than 120 seconds have passed since the last batch update ...

You'll need access to Redis or Memcached to use this feature though. More details here.

pacifier007 commented 2 years ago

I did all that but it's not doing anything in memory. Everything is updating right away. Can you link me to the code that handles it so I can investigate it?

I searched for WPP_CACHE_VIEWS constant but couldn't find any relevant code. And there's no code to store it in-memory. It's updating it right away:

https://github.com/cabrerahector/wordpress-popular-posts/blob/master/src/Front/Front.php#L240

cabrerahector commented 2 years ago

What version of WPP are you using?

(Plus you're looking in the wrong place, it's here.)

pacifier007 commented 2 years ago

Sorry my bad. Thanks for clarifying. I was using a custom JS implementation that doesn't use REST end-point, but the AJAX endpoint.

Is the AJAX code still used anywhere or it is deprecated?

You can close it now. Thanks.

cabrerahector commented 2 years ago

If by "AJAX code" you're referring to this then it should still work, yeah. Haven't tested it in a while though.

If it's not that then please share more details.

pacifier007 commented 2 years ago

That's correct. Or specifically this one: https://wordpress.org/support/topic/updating-the-views-count-via-ajax/

Basically, it uses the wp_ajax_nopriv_update_views_ajax which uses the update_views method in Front.php.

It's a very clear switch to REST for me. Not a problem at all, was just letting you know if that's some dead code in Front.php, that can be cleaned up :)

cabrerahector commented 2 years ago

Ah, yeah that's super old hahaha.

WPP has been using the REST API since May 2018, nearly four years ago now :) All the admin-ajax.php stuff (the front-end stuff) has been removed from the plugin since then.