[wp-trac] [WordPress Trac] #54221: _transient_dirsize_cache is set to autoload=yes and kills db performance if it grows (20MB in our case)

WordPress Trac noreply at wordpress.org
Sat Oct 29 21:47:07 UTC 2022


#54221: _transient_dirsize_cache is set to autoload=yes and kills db performance if
it grows (20MB in our case)
--------------------------+------------------------------------------
 Reporter:  archon810     |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  Database      |     Version:  2.8
 Severity:  major         |  Resolution:
 Keywords:  needs-patch   |     Focuses:  administration, performance
--------------------------+------------------------------------------

Comment (by giuse):

 Hello, I wonder why we need to store all the sizes of all directories. Why
 don't we store just the total size? It would be a number, not a so huge
 array.
 I don't see anywhere in the core the need to know all the sizes, but only
 the global size.
 When you upload or delete a file you can update that single number, and
 that's it.
 Maybe you can calculate again the total size every time you upload or
 delete a file, but I would never save all the details in a transient. For
 what reason?
 Probably, I missing something. Where do you need so much detailed
 information?

 As I see in the core files the function get_dirsize() is used only wp-
 includes/ms-functions.php.

 Here are the lines of code where it is used:

 {{{#!php
 <?php
 $upload_dir = wp_upload_dir();
 $space_used = get_dirsize( $upload_dir['basedir'] ) / MB_IN_BYTES;
 }}}


 Then the function get_dirsizes() calls the function recurse_dirsize()
 which is defined in wp-includes/functions.php. Inside this last function,
 we have get_transient( 'dirsize_cache' ).
 In no other place in the core, do I see anything that needs to get the
 transient 'dirsize_cache'.

 So we have this huge option only to easily get the size of the upload
 directory? One for one single value?


 Are we boating the database and slowing down every page because of
 information that nobody needs? And this option is even autoloaded?

 And this is still not fixed?

 If I'm not missing anything I would only store the total size of the
 upload directory, and nothing else.

 Or if someone knows that in some situations we need all the details,
 please let us know.

 For me it's not a matter of autoloading or not autoloading, it's a matter
 of whether we need or we don't need all the details. And if we need them,
 they must not be autoloaded, no doubt about that. This is a serious issue
 for performance and should be very urgent.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54221#comment:29>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list