Changeset 2103 for branches/release-36/php/lib/mtdb_base.php
- Timestamp:
- 04/25/08 11:36:53 (19 months ago)
- Files:
-
- 1 modified
-
branches/release-36/php/lib/mtdb_base.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/release-36/php/lib/mtdb_base.php
r2091 r2103 413 413 } 414 414 415 function &fetch_entries($args ) {415 function &fetch_entries($args, &$total_count = NULL) { 416 416 if ($sql = $this->include_exclude_blogs($args)) { 417 417 $blog_filter = 'and entry_blog_id ' . $sql; … … 422 422 } 423 423 424 $pagination = 0; 424 425 # automatically include offset if in request 425 426 if ($args['offset'] == 'auto') { 427 $pagination = 1; 426 428 $args['offset'] = 0; 427 429 if ($args['limit'] || $args['lastn']) { … … 801 803 $post_select_limit = $rco; 802 804 $no_resort = 1; 805 } elseif ( !is_null($total_count) ) { 806 $orig_limit = $limit; 807 $orig_offset = $offset; 803 808 } else { 804 809 $sql = $this->apply_limit_sql($sql . " <LIMIT>", $limit, $offset); … … 810 815 $entries = array(); 811 816 $j = 0; 812 $offset = $post_select_offset ? $post_select_offset : 0;817 $offset = $post_select_offset ? $post_select_offset : $orig_offset; 813 818 $limit = $post_select_limit ? $post_select_limit : 0; 814 819 $id_list = array(); 820 $_total_count = 0; 815 821 while (true) { 816 822 $e = $this->query_fetch(ARRAY_A); … … 826 832 } 827 833 } 834 $_total_count++; 835 if ( !is_null($total_count) ) { 836 if ( ($orig_limit > 0) 837 && ( ($_total_count-$offset) > $orig_limit) ) { 838 // collected all the entries; only count numbers; 839 continue; 840 } 841 } 828 842 if ($offset && ($j++ < $offset)) continue; 829 843 $e['entry_authored_on'] = $this->db2ts($e['entry_authored_on']); … … 833 847 $this->_comment_count_cache[$e['entry_id']] = $e['entry_comment_count']; 834 848 $this->_ping_count_cache[$e['entry_id']] = $e['entry_ping_count']; 835 if (($limit > 0) && (count($entries) >= $limit)) break; 849 if ( is_null($total_count) ) { 850 // the request does not want total count; break early 851 if (($limit > 0) && (count($entries) >= $limit)) break; 852 } 853 } 854 if ( !is_null($total_count) ) { 855 $total_count = $_total_count; 836 856 } 837 857
