[wp-trac] [WordPress Trac] #19879: Better caching for get_dirsize

WordPress Trac noreply at wordpress.org
Mon Nov 30 10:12:02 UTC 2015


#19879: Better caching for get_dirsize
----------------------------+-------------------------------------
 Reporter:  batmoo          |       Owner:
     Type:  enhancement     |      Status:  new
 Priority:  normal          |   Milestone:  Future Release
Component:  Filesystem API  |     Version:  3.3.1
 Severity:  normal          |  Resolution:
 Keywords:  needs-patch     |     Focuses:  multisite, performance
----------------------------+-------------------------------------

Comment (by A5hleyRich):

 Supplied patch removes transient timeout as suggested by @nacin. However,
 instead of purging the entire cache the `dirsize_cache` transient now
 caches each directory like so:

 {{{#!php
 <?php
 Array
 (
     [wp-content/uploads/2013/09] => 2082994
     [wp-content/uploads/2013] => 2082994
     [wp-content/uploads/2014/01] => 2082994
     [wp-content/uploads/2014] => 2082994
     [wp-content/uploads/2015/04] => 486873
     [wp-content/uploads/2015/10] => 2919469
     [wp-content/uploads/2015/11] => 34562447
     [wp-content/uploads/2015] => 37968789
     [wp-content/uploads] => 42142973
 )
 }}}

 When `wp_handle_upload()` or `wp_delete_attachment()` are called only the
 directories that are effected are purged. For example if we upload `wp-
 content/uploads/2015/11/test.png` the `_transient_dirsize_cache` becomes:

 {{{#!php
 <?php
 Array
 (
     [wp-content/uploads/2013/09] => 2082994
     [wp-content/uploads/2013] => 2082994
     [wp-content/uploads/2014/01] => 2082994
     [wp-content/uploads/2014] => 2082994
     [wp-content/uploads/2015/04] => 486873
     [wp-content/uploads/2015/10] => 2919469
 )
 }}}


 This ensures that only the changed directories are checked when
 `get_dirsize` is called. Still needs unit tests, but wanted to get
 feedback before doing any more work on this patch.

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


More information about the wp-trac mailing list