Changeset 5555 for trunk/wp-includes/post.php
- Timestamp:
- 05/26/2007 11:32:06 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r5553 r5555 413 413 if ( 'publish' == $post->post_status && 'post' == $post->post_type ) { 414 414 $categories = wp_get_post_categories($post->ID); 415 if ( is_array( $categories ) ) {415 if ( is_array( $categories ) ) { 416 416 foreach ( $categories as $cat_id ) { 417 417 $wpdb->query("UPDATE $wpdb->categories SET category_count = category_count - 1 WHERE cat_ID = '$cat_id'"); … … 1595 1595 } 1596 1596 1597 function get_lastpostdate($timezone = 'server') { 1598 global $cache_lastpostdate, $pagenow, $wpdb, $blog_id; 1599 $add_seconds_blog = get_option('gmt_offset') * 3600; 1600 $add_seconds_server = date('Z'); 1601 if ( !isset($cache_lastpostdate[$blog_id][$timezone]) ) { 1602 switch(strtolower($timezone)) { 1603 case 'gmt': 1604 $lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1"); 1605 break; 1606 case 'blog': 1607 $lastpostdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1"); 1608 break; 1609 case 'server': 1610 $lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1"); 1611 break; 1612 } 1613 $cache_lastpostdate[$blog_id][$timezone] = $lastpostdate; 1614 } else { 1615 $lastpostdate = $cache_lastpostdate[$blog_id][$timezone]; 1616 } 1617 return $lastpostdate; 1618 } 1619 1620 function get_lastpostmodified($timezone = 'server') { 1621 global $cache_lastpostmodified, $pagenow, $wpdb, $blog_id; 1622 $add_seconds_blog = get_option('gmt_offset') * 3600; 1623 $add_seconds_server = date('Z'); 1624 if ( !isset($cache_lastpostmodified[$blog_id][$timezone]) ) { 1625 switch(strtolower($timezone)) { 1626 case 'gmt': 1627 $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1"); 1628 break; 1629 case 'blog': 1630 $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1"); 1631 break; 1632 case 'server': 1633 $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1"); 1634 break; 1635 } 1636 $lastpostdate = get_lastpostdate($timezone); 1637 if ( $lastpostdate > $lastpostmodified ) { 1638 $lastpostmodified = $lastpostdate; 1639 } 1640 $cache_lastpostmodified[$blog_id][$timezone] = $lastpostmodified; 1641 } else { 1642 $lastpostmodified = $cache_lastpostmodified[$blog_id][$timezone]; 1643 } 1644 return $lastpostmodified; 1645 } 1646 1647 // 1648 // Cache 1649 // 1650 1651 function update_post_cache(&$posts) { 1652 global $post_cache, $blog_id; 1653 1654 if ( !$posts ) 1655 return; 1656 1657 for ($i = 0; $i < count($posts); $i++) { 1658 $post_cache[$blog_id][$posts[$i]->ID] = &$posts[$i]; 1659 } 1660 } 1661 1662 function clean_post_cache($id) { 1663 global $post_cache, $post_meta_cache, $category_cache, $tag_cache, $blog_id; 1664 1665 if ( isset( $post_cache[$blog_id][$id] ) ) 1666 unset( $post_cache[$blog_id][$id] ); 1667 1668 if ( isset ($post_meta_cache[$blog_id][$id] ) ) 1669 unset( $post_meta_cache[$blog_id][$id] ); 1670 1671 if ( isset( $category_cache[$blog_id][$id]) ) 1672 unset ( $category_cache[$blog_id][$id] ); 1673 1674 if ( isset( $tag_cache[$blog_id][$id]) ) 1675 unset ( $tag_cache[$blog_id][$id] ); 1676 } 1677 1678 function update_page_cache(&$pages) { 1679 global $page_cache, $blog_id; 1680 1681 if ( !$pages ) 1682 return; 1683 1684 for ($i = 0; $i < count($pages); $i++) { 1685 $page_cache[$blog_id][$pages[$i]->ID] = &$pages[$i]; 1686 wp_cache_add($pages[$i]->ID, $pages[$i], 'pages'); 1687 } 1688 } 1689 1690 function clean_page_cache($id) { 1691 global $page_cache, $blog_id; 1692 1693 if ( isset( $page_cache[$blog_id][$id] ) ) 1694 unset( $page_cache[$blog_id][$id] ); 1695 1696 wp_cache_delete($id, 'pages'); 1697 wp_cache_delete( 'all_page_ids', 'pages' ); 1698 wp_cache_delete( 'get_pages', 'page' ); 1699 } 1700 1701 function update_post_category_cache($post_ids) { 1702 global $wpdb, $category_cache, $tag_cache, $blog_id; 1703 // TODO 1704 return; 1705 if ( empty($post_ids) ) 1706 return; 1707 1708 if ( is_array($post_ids) ) 1709 $post_id_list = implode(',', $post_ids); 1710 1711 $post_id_array = (array) explode(',', $post_ids); 1712 $count = count( $post_id_array); 1713 for ( $i = 0; $i < $count; $i++ ) { 1714 $post_id = (int) $post_id_array[ $i ]; 1715 if ( isset( $category_cache[$blog_id][$post_id] ) ) { 1716 unset( $post_id_array[ $i ] ); 1717 continue; 1718 } 1719 } 1720 if ( count( $post_id_array ) == 0 ) 1721 return; 1722 $post_id_list = join( ',', $post_id_array ); // with already cached stuff removed 1723 1724 $dogs = $wpdb->get_results("SELECT post_id, category_id, rel_type FROM $wpdb->post2cat WHERE post_id IN ($post_id_list)"); 1725 1726 if ( empty($dogs) ) 1727 return; 1728 1729 foreach ($dogs as $catt) { 1730 if ( 'category' == $catt->rel_type ) 1731 $category_cache[$blog_id][$catt->post_id][$catt->category_id] = &get_category($catt->category_id); 1732 elseif ( 'tag' == $catt->rel_type ) 1733 $tag_cache[$blog_id][$catt->post_id][$catt->category_id] = &get_category($catt->category_id); 1734 } 1735 } 1736 1737 function update_post_caches(&$posts) { 1738 global $post_cache, $category_cache, $post_meta_cache, $tag_cache; 1739 global $wpdb, $blog_id; 1740 1741 // No point in doing all this work if we didn't match any posts. 1742 if ( !$posts ) 1743 return; 1744 1745 // Get the categories for all the posts 1746 for ($i = 0; $i < count($posts); $i++) { 1747 $post_id_array[] = $posts[$i]->ID; 1748 $post_cache[$blog_id][$posts[$i]->ID] = &$posts[$i]; 1749 } 1750 1751 $post_id_list = implode(',', $post_id_array); 1752 1753 update_post_category_cache($post_id_list); 1754 1755 update_postmeta_cache($post_id_list); 1756 } 1757 1758 function update_postmeta_cache($post_id_list = '') { 1759 global $wpdb, $post_meta_cache, $blog_id; 1760 1761 // We should validate this comma-separated list for the upcoming SQL query 1762 $post_id_list = preg_replace('|[^0-9,]|', '', $post_id_list); 1763 1764 if ( empty( $post_id_list ) ) 1765 return false; 1766 1767 // we're marking each post as having its meta cached (with no keys... empty array), to prevent posts with no meta keys from being queried again 1768 // any posts that DO have keys will have this empty array overwritten with a proper array, down below 1769 $post_id_array = (array) explode(',', $post_id_list); 1770 $count = count( $post_id_array); 1771 for ( $i = 0; $i < $count; $i++ ) { 1772 $post_id = (int) $post_id_array[ $i ]; 1773 if ( isset( $post_meta_cache[$blog_id][$post_id] ) ) { // If the meta is already cached 1774 unset( $post_id_array[ $i ] ); 1775 continue; 1776 } 1777 $post_meta_cache[$blog_id][$post_id] = array(); 1778 } 1779 if ( count( $post_id_array ) == 0 ) 1780 return; 1781 $post_id_list = join( ',', $post_id_array ); // with already cached stuff removeds 1782 1783 // Get post-meta info 1784 if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id IN($post_id_list) ORDER BY post_id, meta_key", ARRAY_A) ) { 1785 // Change from flat structure to hierarchical: 1786 if ( !isset($post_meta_cache) ) 1787 $post_meta_cache[$blog_id] = array(); 1788 1789 foreach ($meta_list as $metarow) { 1790 $mpid = (int) $metarow['post_id']; 1791 $mkey = $metarow['meta_key']; 1792 $mval = $metarow['meta_value']; 1793 1794 // Force subkeys to be array type: 1795 if ( !isset($post_meta_cache[$blog_id][$mpid]) || !is_array($post_meta_cache[$blog_id][$mpid]) ) 1796 $post_meta_cache[$blog_id][$mpid] = array(); 1797 if ( !isset($post_meta_cache[$blog_id][$mpid]["$mkey"]) || !is_array($post_meta_cache[$blog_id][$mpid]["$mkey"]) ) 1798 $post_meta_cache[$blog_id][$mpid]["$mkey"] = array(); 1799 1800 // Add a value to the current pid/key: 1801 $post_meta_cache[$blog_id][$mpid][$mkey][] = $mval; 1802 } 1803 } 1804 } 1805 1597 1806 ?>
Note: See TracChangeset
for help on using the changeset viewer.