Changeset 22879
- Timestamp:
- May 26, 2013, 9:56:31 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/category_cats.inc.php
r21802 r22879 38 38 max_date_last, 39 39 count_images, 40 nb_categories, 40 41 count_categories 41 42 FROM '.CATEGORIES_TABLE.' c … … 120 121 if ($conf['representative_cache_on_subcats'] and $row['user_representative_picture_id'] != $image_id) 121 122 { 122 $user_representative_updates_for[ $ user['id'].'#'.$row['id'] ] = $image_id;123 $user_representative_updates_for[ $row['id'] ] = $image_id; 123 124 } 124 125 … … 212 213 if ($conf['representative_cache_on_level']) 213 214 { 214 $user_representative_updates_for[ $ user['id'].'#'.$category['id'] ] = $image_id;215 $user_representative_updates_for[ $category['id'] ] = $image_id; 215 216 } 216 217 … … 247 248 $updates = array(); 248 249 249 foreach ($user_representative_updates_for as $user_cat => $image_id) 250 { 251 list($user_id, $cat_id) = explode('#', $user_cat); 252 253 array_push( 254 $updates, 250 foreach ($user_representative_updates_for as $cat_id => $image_id) 251 { 252 $updates[] = 255 253 array( 256 'user_id' => $user _id,254 'user_id' => $user['id'], 257 255 'cat_id' => $cat_id, 258 256 'user_representative_picture_id' => $image_id, 259 ) 260 ); 257 ); 261 258 } 262 259 -
trunk/include/functions_user.inc.php
r22005 r22879 411 411 { 412 412 $forbidden_ids[] = $cat['cat_id']; 413 unset( $user_cache_cats[$cat['cat_id']]);413 remove_computed_category($user_cache_cats, $cat); 414 414 } 415 415 } … … 442 442 ( 443 443 'user_id', 'cat_id', 444 'date_last', 'max_date_last', 'nb_images', 'count_images', ' count_categories'444 'date_last', 'max_date_last', 'nb_images', 'count_images', 'nb_categories', 'count_categories' 445 445 ), 446 446 $user_cache_cats, … … 603 603 } 604 604 605 /** 606 * compute data of categories branches (one branch only) 607 */ 608 function compute_branch_cat_data(&$cats, &$list_cat_id, &$level, &$ref_level) 609 { 610 $date = ''; 611 $count_images = 0; 612 $count_categories = 0; 613 do 614 { 615 $cat_id = array_pop($list_cat_id); 616 if (!is_null($cat_id)) 617 { 618 // Count images and categories 619 $cats[$cat_id]['count_images'] += $count_images; 620 $cats[$cat_id]['count_categories'] += $count_categories; 621 $count_images = $cats[$cat_id]['count_images']; 622 $count_categories = $cats[$cat_id]['count_categories'] + 1; 623 624 if ((empty($cats[$cat_id]['max_date_last'])) or ($cats[$cat_id]['max_date_last'] < $date)) 625 { 626 $cats[$cat_id]['max_date_last'] = $date; 627 } 628 else 629 { 630 $date = $cats[$cat_id]['max_date_last']; 631 } 632 $ref_level = substr_count($cats[$cat_id]['global_rank'], '.') + 1; 633 } 634 else 635 { 636 $ref_level = 0; 637 } 638 } while ($level <= $ref_level); 639 640 // Last cat updating must be added to list for next branch 641 if ($ref_level <> 0) 642 { 643 $list_cat_id[] = $cat_id; 644 } 645 } 646 647 /** 648 * compute data of categories branches 649 */ 650 function compute_categories_data(&$cats) 651 { 652 $ref_level = 0; 653 $level = 0; 654 $list_cat_id = array(); 655 656 foreach ($cats as $id => $category) 657 { 658 // Compute 659 $level = substr_count($category['global_rank'], '.') + 1; 660 if ($level > $ref_level) 661 { 662 $list_cat_id[] = $id; 663 } 664 else 665 { 666 compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level); 667 $list_cat_id[] = $id; 668 } 669 $ref_level = $level; 670 } 671 672 $level = 1; 673 compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level); 605 606 /*update counters with a category removal*/ 607 function remove_computed_category(&$cats, $cat) 608 { 609 if ( isset( $cats[$cat['id_uppercat']] ) ) 610 { 611 $parent = & $cats[ $cat['id_uppercat'] ]; 612 $parent['nb_categories']--; 613 614 do 615 { 616 617 $parent['count_images'] -= $cat['nb_images']; 618 $parent['count_categories'] -= 1+$cat['count_categories']; 619 620 if ( !isset( $cats[$parent['id_uppercat']] ) ) 621 break; 622 $parent = & $cats[$parent['id_uppercat']]; 623 } 624 while (true); 625 } 626 627 unset($cats[$cat['cat_id']]); 674 628 } 675 629 … … 683 637 function get_computed_categories(&$userdata, $filter_days=null) 684 638 { 685 $query = 'SELECT c.id AS cat_id, global_rank';639 $query = 'SELECT c.id AS cat_id, id_uppercat'; 686 640 // Count by date_available to avoid count null 687 641 $query .= ', … … 714 668 { 715 669 $row['user_id'] = $userdata['id']; 670 $row['nb_categories'] = 0; 716 671 $row['count_categories'] = 0; 717 672 $row['count_images'] = (int)$row['nb_images']; … … 722 677 } 723 678 724 $cats += array($row['cat_id'] => $row); 725 } 726 uasort($cats, 'global_rank_compare'); 727 728 compute_categories_data($cats); 679 $cats[$row['cat_id']] = $row; 680 } 681 682 foreach ($cats as $cat) 683 { 684 if ( !isset( $cat['id_uppercat'] ) ) 685 continue; 686 687 $parent = & $cats[ $cat['id_uppercat'] ]; 688 $parent['nb_categories']++; 689 690 do 691 { 692 $parent['count_images'] += $cat['nb_images']; 693 $parent['count_categories']++; 694 695 if ((empty($parent['max_date_last'])) or ($parent['max_date_last'] < $cat['date_last'])) 696 { 697 $parent['max_date_last'] = $cat['date_last']; 698 } 699 700 if ( !isset( $parent['id_uppercat'] ) ) 701 break; 702 $parent = & $cats[$parent['id_uppercat']]; 703 } 704 while (true); 705 unset($parent); 706 } 729 707 730 708 if ( isset($filter_days) ) 731 709 { 732 $cat_tmp = $cats; 733 $cats = array(); 734 735 foreach ($cat_tmp as $category) 736 { 737 if (!empty($category['max_date_last'])) 738 { 739 // Re-init counters 740 $category['count_categories'] = 0; 741 $category['count_images'] = (int)$category['nb_images']; 742 // Keep category 743 $cats[$category['cat_id']] = $category; 744 } 745 } 746 // Compute a second time 747 compute_categories_data($cats); 710 foreach ($cats as $category) 711 { 712 if (empty($category['max_date_last'])) 713 { 714 remove_computed_category($cats, $category); 715 } 716 } 748 717 } 749 718 return $cats; -
trunk/install/piwigo_structure-mysql.sql
r22134 r22879 373 373 `nb_images` mediumint(8) unsigned NOT NULL default '0', 374 374 `count_images` mediumint(8) unsigned default '0', 375 `nb_categories` mediumint(8) unsigned default '0', 375 376 `count_categories` mediumint(8) unsigned default '0', 376 377 `user_representative_picture_id` mediumint(8) unsigned default NULL,
Note: See TracChangeset
for help on using the changeset viewer.