From: <in...@us...> - 2003-03-10 09:41:05
|
Update of /cvsroot/mantisbt/mantisbt/core In directory sc8-pr-cvs1:/tmp/cvs-serv18762/core Modified Files: obsolete.php summary_api.php Log Message: * config_defaults_inc.php: Removed obsolete config option g_summary_pad * core/obsolete.php: Added obsolete config option g_summary_pad * core/summary_api.php: Significantly reduced the number of SQL queries executed to build summary page. Index: obsolete.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/obsolete.php,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- obsolete.php 5 Mar 2003 21:37:31 -0000 1.18 +++ obsolete.php 10 Mar 2003 09:40:55 -0000 1.19 @@ -74,4 +74,6 @@ config_obsolete( 'bug_file_upload_inc', '' ); config_obsolete( 'show_source', '' ); + + config_obsolete( 'summary_pad', '' ); ?> Index: summary_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/summary_api.php,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- summary_api.php 9 Mar 2003 03:08:59 -0000 1.12 +++ summary_api.php 10 Mar 2003 09:40:55 -0000 1.13 @@ -13,12 +13,22 @@ # Summary printing API ########################################################################### + function summary_helper_print_row( $row, $label, $open, $resolved, $closed, $total ) { + printf( "<tr %s>", helper_alternate_class( $row ) ); + printf( "<td width=\"50%%\">%s</td>", $label ); + printf( "<td width=\"12%%\" class=\"right\">%d</td>", $open ); + printf( "<td width=\"12%%\" class=\"right\">%d</td>", $resolved ); + printf( "<td width=\"12%%\" class=\"right\">%d</td>", $closed ); + printf( "<td width=\"12%%\" class=\"right\">%d</td>", $total ); + print( "</tr>\n" ); + } # -------------------- # Used in summary reports - # Given the enum string this function prints out the summary for each enum setting + # Given the enum string this function prints out the summary + # for each enum setting # The enum field name is passed in through $p_enum function print_bug_enum_summary( $p_enum_string, $p_enum ) { - global $g_mantis_bug_table, $g_summary_pad; + global $g_mantis_bug_table; $t_arr = explode_enum_string( $p_enum_string ); $enum_count = count( $t_arr ); @@ -26,57 +36,62 @@ $t_project_id = helper_get_current_project(); #checking if it's a per project statistic or all projects - if ( ALL_PROJECTS == $t_project_id ) $specific_where = ' 1=1'; - else $specific_where = " project_id='$t_project_id'"; + if ( ALL_PROJECTS == $t_project_id ) + $specific_where = ' 1=1'; + else + $specific_where = " project_id='$t_project_id'"; - for ($i=0;$i<$enum_count;$i++) { - $t_s = explode_enum_arr( $t_arr[$i] ); - $c_s[0] = addslashes($t_s[0]); + $query = "SELECT status, $p_enum FROM $g_mantis_bug_table" + . " WHERE $specific_where ORDER BY $p_enum"; - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE $p_enum='$c_s[0]' AND $specific_where"; - $result = db_query( $query ); - $t_enum_count = db_result( $result, 0 ); + $result = db_query( $query ); - $t_res_val = RESOLVED; - $t_clo_val = CLOSED; - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE $p_enum='$c_s[0]' AND - status<>'$t_res_val' AND - status<>'$t_clo_val' AND $specific_where"; - $result2 = db_query( $query ); - $open_bug_count = db_result( $result2, 0, 0 ); + $last_value = -1; + $bugs_open = 0; + $bugs_resolved = 0; + $bugs_closed = 0; + $bugs_total = 0; - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE $p_enum='$c_s[0]' AND - status='$t_clo_val' AND $specific_where"; - $result2 = db_query( $query ); - $closed_bug_count = db_result( $result2, 0, 0 ); + $t_resolved_val = RESOLVED; + $t_closed_val = CLOSED; - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE $p_enum='$c_s[0]' AND - status='$t_res_val' AND $specific_where"; - $result2 = db_query( $query ); - $resolved_bug_count = db_result( $result2, 0, 0 ); + while ( $row = db_fetch_array( $result ) ) { + if ( $row[$p_enum] != $last_value + && $last_value != -1 ) { + summary_helper_print_row( $i + , get_enum_element( $p_enum, $last_value) + , $bugs_open, $bugs_resolved + , $bugs_closed, $bugs_total ); - $open_bug_count = str_pad( $open_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); - $resolved_bug_count = str_pad( $resolved_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); - $closed_bug_count = str_pad( $closed_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); - $t_enum_count = str_pad( $t_enum_count, ' ', $g_summary_pad, STR_PAD_LEFT ); + $bugs_open = 0; + $bugs_resolved = 0; + $bugs_closed = 0; + $bugs_total = 0; + } - print '<tr align="center" ' . helper_alternate_class( $i ) . '>'; - PRINT "<td width=\"50%\">"; - echo get_enum_element( $p_enum, $t_s[0] ); - PRINT '</td>'; - PRINT "<td width=\"50%\">"; - PRINT "$open_bug_count / $resolved_bug_count / $closed_bug_count / $t_enum_count"; - PRINT '</td>'; - PRINT '</tr>'; - } # end for + $bugs_total++; + + switch( $row['status'] ) { + case $t_resolved_val: + $bugs_resolved++; + break; + case $t_closed_val: + $bugs_closed++; + break; + default: + $bugs_open++; + break; + } + + $last_value = $row[$p_enum]; + } + + if ( 0 < $bugs_total ) { + summary_helper_print_row( $i + , get_enum_element( $p_enum, $last_value) + , $bugs_open, $bugs_resolved + , $bugs_closed, $bugs_total ); + } } # -------------------- # prints the bugs submitted in the last X days (default is 1 day) for the @@ -106,236 +121,246 @@ for ($i=0;$i<$arr_count;$i++) { $t_enum_count = get_bug_count_by_date( $p_date_array[$i] ); - print '<tr align="center" ' . helper_alternate_class( $i ) . '>'; - PRINT "<td width=\"50%\">"; - echo $p_date_array[$i]; - PRINT '</td>'; - PRINT "<td width=\"50%\">"; - echo $t_enum_count; - PRINT '</td>'; - PRINT '</tr>'; + printf( "<tr %s>", helper_alternate_class( $row ) ); + printf( "<td width=\"50%%\">%s</td>", $p_date_array[$i] ); + printf( "<td class=\"right\">%s</td>", $t_enum_count ); + print( "</tr>\n" ); } # end for } # -------------------- # print bug counts by assigned to each developer function print_developer_summary() { - global $g_mantis_bug_table, $g_mantis_user_table, - $g_summary_pad, $g_handle_bug_threshold; + global $g_mantis_bug_table, $g_mantis_user_table; + + $t_project_id = helper_get_current_project(); - $t_dev = $g_handle_bug_threshold; - $t_man = MANAGER; - $t_adm = ADMINISTRATOR; + if ( ALL_PROJECTS == $t_project_id ) + $specific_where = ' 1=1'; + else + $specific_where = " project_id='$t_project_id'"; - $query = "SELECT id, username - FROM $g_mantis_user_table - ORDER BY username"; - $result = db_query( $query ); - $user_count = db_num_rows( $result ); + $query = "SELECT handler_id, status FROM $g_mantis_bug_table" + . " WHERE handler_id>0 AND $specific_where" + . " ORDER BY handler_id"; - $t_project_id = helper_get_current_project(); + $result = db_query( $query ); - #checking if it's a per project statistic or all projects - if ( ALL_PROJECTS == $t_project_id ) $specific_where = ' 1=1'; - else $specific_where = " project_id='$t_project_id'"; + $last_handler = -1; + $bugs_open = 0; + $bugs_resolved = 0; + $bugs_closed = 0; + $bugs_total = 0; - $t_row_count = 0; + $t_resolved_val = RESOLVED; + $t_closed_val = CLOSED; - for ($i=0;$i<$user_count;$i++) { - $row = db_fetch_array( $result ); + while ( $row = db_fetch_array( $result ) ) { extract( $row, EXTR_PREFIX_ALL, 'v' ); - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE handler_id='$v_id' AND $specific_where"; - $result2 = db_query( $query ); - $total_bug_count = db_result( $result2, 0, 0 ); - - #only developers with relevant stats are displayed - if ($total_bug_count>0) { - $t_res_val = RESOLVED; - $t_clo_val = CLOSED; - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE handler_id='$v_id' AND - status<>'$t_res_val' AND - status<>'$t_clo_val' AND $specific_where"; - $result2 = db_query( $query ); - $open_bug_count = db_result( $result2, 0, 0 ); + if ( $v_handler_id != $last_handler + && $last_handler != -1 ) { + $query = "SELECT username" + . " FROM $g_mantis_user_table" + . " WHERE id=$last_handler"; + $result2 = db_query( $query ); + $row2 = db_fetch_array( $result2 ); + summary_helper_print_row( $i + , $row2['username'] + , $bugs_open, $bugs_resolved + , $bugs_closed, $bugs_total ); - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE handler_id='$v_id' AND status='$t_clo_val' AND $specific_where"; - $result2 = db_query( $query ); - $closed_bug_count = db_result( $result2, 0, 0 ); + $bugs_open = 0; + $bugs_resolved = 0; + $bugs_closed = 0; + $bugs_total = 0; + } - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE handler_id='$v_id' AND status='$t_res_val' AND $specific_where"; - $result2 = db_query( $query ); - $resolved_bug_count = db_result( $result2, 0, 0 ); + $bugs_total++; - $open_bug_count = str_pad( $open_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); - $resolved_bug_count = str_pad( $resolved_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); - $closed_bug_count = str_pad( $closed_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); - $total_bug_count = str_pad( $total_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); + switch( $v_status ) { + case $t_resolved_val: + $bugs_resolved++; + break; + case $t_closed_val: + $bugs_closed++; + break; + default: + $bugs_open++; + break; + } - print '<tr align="center" ' . helper_alternate_class( $i ) . '>'; - PRINT "<td width=\"50%\">"; - echo $v_username; - PRINT '</td>'; - PRINT "<td width=\"50%\">"; - PRINT "$open_bug_count / $resolved_bug_count / $closed_bug_count / $total_bug_count"; - PRINT '</td>'; - PRINT '</tr>'; + $last_handler = $v_handler_id; + } - $t_row_count++; - } #end if - } # end for + if ( 0 < $bugs_total ) { + $query = "SELECT username" + . " FROM $g_mantis_user_table" + . " WHERE id=$last_handler"; + $result2 = db_query( $query ); + $row2 = db_fetch_array( $result2 ); + summary_helper_print_row( $i + , $row2['username'] + , $bugs_open, $bugs_resolved + , $bugs_closed, $bugs_total ); + } } # -------------------- # print bug counts by reporter id function print_reporter_summary() { - global $g_mantis_bug_table, - $g_reporter_summary_limit, - $g_summary_pad; - + global $g_mantis_bug_table, $g_mantis_user_table; + global $g_reporter_summary_limit; + $t_project_id = helper_get_current_project(); - #checking if it's a per project statistic or all projects - if ( ALL_PROJECTS == $t_project_id ) $specific_where = ' 1=1'; - else $specific_where = " project_id='$t_project_id'"; + if ( ALL_PROJECTS == $t_project_id ) + $specific_where = ' 1=1'; + else + $specific_where = " project_id='$t_project_id'"; - $t_view = VIEWER; - $query = "SELECT reporter_id, COUNT(*) as num - FROM $g_mantis_bug_table - WHERE $specific_where - GROUP BY reporter_id - ORDER BY num DESC - LIMIT $g_reporter_summary_limit"; + $query = "SELECT reporter_id, COUNT(*) as num" + . " FROM $g_mantis_bug_table" + . " WHERE $specific_where" + . " GROUP BY reporter_id" + . " ORDER BY num DESC" + . " LIMIT $g_reporter_summary_limit"; $result = db_query( $query ); - $user_count = db_num_rows( $result ); - for ($i=0;$i<$user_count;$i++) { - $row = db_fetch_array( $result ); - - $v_id = $row['reporter_id']; - $v_username = user_get_name( $v_id ); - - $t_res_val = RESOLVED; - $t_clo_val = CLOSED; - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE reporter_id='$v_id' AND $specific_where "; + while ( $row = db_fetch_array( $result ) ) { + $v_reporter_id = $row['reporter_id']; + $query = "SELECT status FROM $g_mantis_bug_table" + . " WHERE reporter_id=$v_reporter_id" + . " AND $specific_where"; $result2 = db_query( $query ); - $total_bug_count = db_result( $result2, 0, 0 ); - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE reporter_id='$v_id' AND - status<>'$t_res_val' AND - status<>'$t_clo_val' AND $specific_where "; - $result2 = db_query( $query ); - $open_bug_count = db_result( $result2, 0, 0 ); + $last_reporter = -1; + $bugs_open = 0; + $bugs_resolved = 0; + $bugs_closed = 0; + $bugs_total = 0; - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE reporter_id='$v_id' AND status='$t_clo_val' AND $specific_where "; - $result2 = db_query( $query ); - $closed_bug_count = db_result( $result2, 0, 0 ); + $t_resolved_val = RESOLVED; + $t_closed_val = CLOSED; - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE reporter_id='$v_id' AND status='$t_res_val' AND $specific_where "; - $result2 = db_query( $query ); - $resolved_bug_count = db_result( $result2, 0, 0 ); + while ( $row2 = db_fetch_array( $result2 ) ) { + $bugs_total++; - $open_bug_count = str_pad( $open_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); - $resolved_bug_count = str_pad( $resolved_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); - $closed_bug_count = str_pad( $closed_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); - $total_bug_count = str_pad( $total_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); + switch( $row2['status'] ) { + case $t_resolved_val: + $bugs_resolved++; + break; + case $t_closed_val: + $bugs_closed++; + break; + default: + $bugs_open++; + break; + } + } - print '<tr align="center" ' . helper_alternate_class( $i ) . '>'; - PRINT "<td width=\"50%\">"; - echo $v_username; - PRINT '</td>'; - PRINT "<td width=\"50%\">"; - PRINT "$open_bug_count / $resolved_bug_count / $closed_bug_count / $total_bug_count"; - PRINT '</td>'; - PRINT '</tr>'; - } # end for + if ( 0 < $bugs_total ) { + $query = "SELECT username" + . " FROM $g_mantis_user_table" + . " WHERE id=$v_reporter_id"; + $result3 = db_query( $query ); + $row3 = db_fetch_array( $result3 ); + summary_helper_print_row( $i + , $row3['username'] + , $bugs_open, $bugs_resolved + , $bugs_closed, $bugs_total ); + } + } } # -------------------- # print a bug count per category function print_category_summary() { - global $g_mantis_bug_table, $g_mantis_project_table, - $g_mantis_project_category_table, - $g_summary_pad, $g_summary_category_include_project; - + global $g_mantis_bug_table; + global $g_mantis_project_table; + global $g_summary_category_include_project; + $t_project_id = helper_get_current_project(); - #checking if it's a per project statistic or all projects - if ( ALL_PROJECTS == $t_project_id ) { - $specific_where = ''; - } else { - $specific_where = " AND (project_id='$t_project_id')"; - } + if ( ALL_PROJECTS == $t_project_id ) + $specific_where = ' 1=1'; + else + $specific_where = " project_id='$t_project_id'"; + + $query = "SELECT project_id, category, status FROM $g_mantis_bug_table" + . " WHERE category>'' AND $specific_where" + . " ORDER BY project_id, category, status"; - $query = "SELECT name as project, category - FROM $g_mantis_project_category_table pc, $g_mantis_project_table p - WHERE (p.id = pc.project_id) $specific_where - ORDER BY project, category"; $result = db_query( $query ); - $category_count = db_num_rows( $result ); - for ($i=0;$i<$category_count;$i++) { - $row = db_fetch_array( $result ); - $t_category = $row['category']; - $t_project = $row['project']; + $last_category = -1; + $last_project = -1; + $bugs_open = 0; + $bugs_resolved = 0; + $bugs_closed = 0; + $bugs_total = 0; - $c_category = addslashes( $t_category ); - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE category='$c_category' $specific_where "; - $result2 = db_query( $query ); - $total_bug_count = db_result( $result2, 0, 0 ); + $t_resolved_val = RESOLVED; + $t_closed_val = CLOSED; - $t_clo_val = CLOSED; - $t_res_val = RESOLVED; + while ( $row = db_fetch_array( $result ) ) { + extract( $row, EXTR_PREFIX_ALL, 'v' ); - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE category='$c_category' AND - status<>'$t_clo_val' AND - status<>'$t_res_val' $specific_where "; - $result2 = db_query( $query ); - $open_bug_count = db_result( $result2, 0, 0 ); + if ( $v_category != $last_category + && $last_category != -1 ) { + $label = $last_category; + if ( ( ON == $g_summary_category_include_project ) + && ( ALL_PROJECTS == $t_project_id ) ) { + $query = "SELECT name" + . " FROM $g_mantis_project_table" + . " WHERE id=$last_project"; + $result2 = db_query( $query ); + $row2 = db_fetch_array( $result2 ); - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE category='$c_category' AND status='$t_clo_val' $specific_where "; - $result2 = db_query( $query ); - $closed_bug_count = db_result( $result2, 0, 0 ); + $label = sprintf( "[%s] %s", $row2['name'], $label ); + } + summary_helper_print_row( $i + , $label + , $bugs_open, $bugs_resolved + , $bugs_closed, $bugs_total ); - $query = "SELECT COUNT(*) - FROM $g_mantis_bug_table - WHERE category='$c_category' AND status='$t_res_val' $specific_where "; - $result2 = db_query( $query ); - $resolved_bug_count = db_result( $result2, 0, 0 ); + $bugs_open = 0; + $bugs_resolved = 0; + $bugs_closed = 0; + $bugs_total = 0; + } - $open_bug_count = str_pad( $open_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); - $resolved_bug_count = str_pad( $resolved_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); - $closed_bug_count = str_pad( $closed_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); - $total_bug_count = str_pad( $total_bug_count, ' ', $g_summary_pad, STR_PAD_LEFT ); + $bugs_total++; - print '<tr align="center" ' . helper_alternate_class( $i ) . '>'; - PRINT "<td width=\"50%\">"; - if ( ( ON == $g_summary_category_include_project ) && ( ALL_PROJECTS == $t_project_id ) ) { - PRINT "[$t_project] "; + switch( $v_status ) { + case $t_resolved_val: + $bugs_resolved++; + break; + case $t_closed_val: + $bugs_closed++; + break; + default: + $bugs_open++; + break; } - PRINT "$t_category</td><td width=\"50%\">"; - PRINT "$open_bug_count / $resolved_bug_count / $closed_bug_count / $total_bug_count"; - PRINT '</td>'; - PRINT '</tr>'; - } # end for + + $last_category = $v_category; + $last_project = $v_project_id; + } + + if ( 0 < $bugs_total ) { + $label = $last_category; + if ( ( ON == $g_summary_category_include_project ) + && ( ALL_PROJECTS == $t_project_id ) ) { + $query = "SELECT name" + . " FROM $g_mantis_project_table" + . " WHERE id=$last_project"; + $result2 = db_query( $query ); + $row2 = db_fetch_array( $result2 ); + + $label = sprintf( "[%s] %s", $row2['name'], $label ); + } + summary_helper_print_row( $i + , $label + , $bugs_open, $bugs_resolved + , $bugs_closed, $bugs_total ); + } } # -------------------- ?> |