• Resolved spinksys

    (@spinksys)


    Hi, while running the WordPress VIP code analysis bot against this plugin I found a bunch of uncached database calls and loose comparison operators. Both of these were middle tier warnings. I’m hoping this can get added to your task backlog and get updated in the plugin in the near future! Thanks!

    Here’s more info on the bot: https://docs.wpvip.com/vip-code-analysis-bot/

    Here are the warnings:

    plugins/wordpress-popular-posts/src/Image.php
    Warning( severity 5 ): Use of a direct database call is discouraged (WordPress.DB.DirectDatabaseQuery.DirectQuery).
    line 484, 572, 632
    Warning( severity 5 ): Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete() (WordPress.DB.DirectDatabaseQuery.NoCaching).
    line 572, 632 plugins/wordpress-popular-posts/src/Query.php
    Warning( severity 5 ): Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete() (WordPress.DB.DirectDatabaseQuery.NoCaching).
    line 502 plugins/wordpress-popular-posts/src/Rest/ViewLoggerEndpoint.php
    Warning( severity 5 ): Use of a direct database call is discouraged (WordPress.DB.DirectDatabaseQuery.DirectQuery).
    line 226, 227
    Warning( severity 5 ): Attempting a database schema change is discouraged (WordPress.DB.DirectDatabaseQuery.SchemaChange).
    line 77 plugins/wordpress-popular-posts/src/template-tags.php
    Warning( severity 5 ): Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete() (WordPress.DB.DirectDatabaseQuery.NoCaching).
    line 146
    Warning( severity 5 ): Use of a direct database call is discouraged (WordPress.DB.DirectDatabaseQuery.DirectQuery).
    line 146 plugins/wordpress-popular-posts/src/Admin/Admin.php
    Warning( severity 5 ): Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete() (WordPress.DB.DirectDatabaseQuery.NoCaching).
    line 249, 379, 952
    Warning( severity 5 ): Use of a direct database call is discouraged (WordPress.DB.DirectDatabaseQuery.DirectQuery).
    line 249, 379, 952 plugins/wordpress-popular-posts/src/Admin/screen-debug.php
    Warning( severity 5 ): Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete() (WordPress.DB.DirectDatabaseQuery.NoCaching).
    line 62, 63
    Warning( severity 5 ): Use of a direct database call is discouraged (WordPress.DB.DirectDatabaseQuery.DirectQuery).
    line 62, 63 plugins/wordpress-popular-posts/src/Widget/form.php
    Warning( severity 3 ): Loose comparisons are not allowed. Expected: "==="; Found: "==" (Universal.Operators.StrictComparisons.LooseEqual).
    line 22, 23, 24, 35, 36, 37, 38, 41, 45, 46, 47, 165, 166, 167, 168, 178, 182, 231, 233 plugins/wordpress-popular-posts/src/Widget/form.php
    Warning( severity 3 ): Loose comparisons are not allowed. Expected: "==="; Found: "==" (Universal.Operators.StrictComparisons.LooseEqual).
    line 125, 138, 163, 164
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @spinksys,

    Thanks for the notice. However know that the plugin actually provides its own data caching mechanism so these warnings can be ignored for the most part:

    • The ones coming from Image.php only run when generating a post thumbnail for the first time. Once it’s generated and cached in /wp-content/uploads/wordpress-popular-posts/ the plugin won’t execute any of these queries again unless a) you delete the thumbnails, or b) the plugin is generating a new thumbnail for the post.
    • Queries generated via Query.php are necessary to build your popular posts list. And, as stated above, the plugin provides a mechanism to cache these queries.
    • Queries from ViewLoggerEndpoint.php are the ones responsible for updating your post/page/CPT views count, caching queries here doesn’t make a lot of sense.
    • From template-tags.php, it might be a good idea to cache the query generated by the wpp_get_views() function so that one I might consider doing.
    • Queries run in Admin/Admin.php and Admin/screen-debug.php are respectively used in the Stats screen (to show you a live view of your popular posts/pages/CPTs) and for debugging purposes. Caching these won’t help performance in any way unless you have millions of users visiting your WP Dashboard, and in such case you’ll want to prioritize optimizing other areas of your site first (eg. beefier hardware, database sharding, Redis, etc.)
    • Warnings coming from /Widget can be completely ignored, the entire /Widget folder contains code related to the “classic” WordPress Popular Posts widget which has been officially deprecated and will be removed from the plugin around June this year (so in less than three months).

    Always consider context when evaluating these warnings from WPCS/PHPCS. Most of the times these are useful, and sometimes they just don’t apply to some use cases.

    Thread Starter spinksys

    (@spinksys)

    Thanks for looking at these – I agree that often the advice isn’t as black and white and the bot suggests.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Thank you for reporting these anyways. I will disable the ones that are false positives to reduce noice so this has been super helpful!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Uncached database calls, and loose comparison warnings’ is closed to new replies.