Opened 2 years ago
Closed 2 years ago
#42021 closed defect (bug) (fixed)
_update_posts_count_on_transition_post_status firing for incorrect post types
| Reported by: |  | Owned by: |  | 
|---|---|---|---|
| Milestone: | 4.9 | Priority: | normal | 
| Severity: | normal | Version: | 4.0 | 
| Component: | Networks and Sites | Keywords: | has-patch needs-unit-tests | 
| Focuses: | multisite | Cc: | 
Description
In a Multisite environment the number of posts (of the posts post_type) is tracked by update_posts_count(). This function will do a large select query which can be pretty slow. The problem is that currently _update_posts_count_on_transition_post_status() will trigger no matter what post type is being transitioned, since update_posts_count() only counts the posts post_type we don't need to trigger a count when a post of another post_type is transitioning.
This patch adds the 3rd parameter to the _update_posts_count_on_transition_post_status() and then does a check and returns if the post is not the post post_type
Attachments (4)
Change History (9)
    
      
    #2
  
    
        
          
             @
 @
            
2 years ago
        
    
  
  
  - Keywords needs-unit-tests added
Added some improvements. For backward compatiblity, I added null to the $posts param to make sure if anyone is calling the function in there own code there is no breakage. 
Also used get_post_type() as it always returns something. 
    
      
    #3
  
    
        
          
             @
 @
            
2 years ago
        
    
  
  
  - Milestone changed from Awaiting Review to 4.9
- Owner set to jeremyfelt
- Status changed from new to reviewing
Good catch, thanks @sboisvert  - this seems like a straight forward fix.
    
      
    #4
  
    
        
          
             @
 @
            
2 years ago
        
    
  
  
    
42021.2.diff applies the same restriction to _update_posts_count_on_delete(), which already has access to the post object.



 
			 
                
Tweaks to @sboisvert 's patch