View Issue Details

IDProjectCategoryView StatusLast Update
0005807mantisbtadministrationpublic2008-08-12 09:35
ReporterSjord Assigned Tograngeway  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionno change required 
Product Version1.0.0a3 
Summary0005807: Performance problems when viewing summary
Description

When viewing the summary for all projects or big projects, loading the page takes too long.

Additional Information

Attached is a patch which changes the "Time Stats For Resolved Issues" part. The output differs a bit from the algorithm of 1.0.0a3. However, it is just not scalable to execute a query for each bug, just to calculate the total time.

TagsNo tags attached.

Relationships

child of 0004181 closed Features in Mantis 1.1 release 

Activities

2005-06-17 09:31

 

timestats.patch (5,954 bytes)   
Index: summary_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/summary_page.php,v
retrieving revision 1.45
diff -u -r1.45 summary_page.php
--- summary_page.php	27 Apr 2005 02:20:13 -0000	1.45
+++ summary_page.php	17 Jun 2005 13:16:01 -0000
@@ -36,71 +42,7 @@
 
 	$t_project_ids = array_map( 'db_prepare_int', $t_project_ids );
 
-	if ( 0 == count( $t_project_ids ) ) {
-		$specific_where = ' 1 <> 1';
-	} elseif ( 1 == count( $t_project_ids ) ) {
-		$specific_where = ' project_id=' . $t_project_ids[0];
-	} else {
-		$specific_where = ' project_id IN (' . join( ',', $t_project_ids ) . ')';
-	}
-
-	$t_bug_table = config_get( 'mantis_bug_table' );
-	$t_history_table = config_get( 'mantis_bug_history_table' );
-
-	$t_clo_val = config_get( 'bug_resolved_status_threshold' );
-	$query = "SELECT id, date_submitted, last_updated, status
-			FROM $t_bug_table
-			WHERE $specific_where AND status>='$t_clo_val'";
-	$result = db_query( $query );
-	$bug_count = db_num_rows( $result );
-
-	$t_bug_id       = 0;
-	$t_largest_diff = 0;
-	$t_total_time   = 0;
-	for ($i=0;$i<$bug_count;$i++) {
-		$row = db_fetch_array( $result );
-		$t_date_submitted = db_unixtimestamp( $row['date_submitted'] );
-		$t_last_updated   = db_unixtimestamp( $row['last_updated'] );
-		$t_id = $row['id'];
-		$t_status = $row['status'];
-
-		# if the status is not the closed value, it may have passed through the
-		#  status we consider closed (e.g., bug is CLOSED, not RESOLVED)
-		#  we should look for the last time it was RESOLVED in the history
-		if ( $t_status <> $t_clo_val ) {
-			$query2 = "SELECT date_modified
-				FROM " . $t_history_table . "
-				WHERE bug_id=$t_id AND type=" . NORMAL_TYPE .
-							" AND field_name='status' AND new_value='$t_clo_val'
-				ORDER BY date_modified DESC";
-			$result2 = db_query( $query2 );
-			if ( db_num_rows( $result2 ) >= 1 ) {
-				# if any were found, read the first (oldest) one and update the timestamp
-				$row2 = db_fetch_array( $result2 );
-				$t_last_updated   = db_unixtimestamp( $row2['date_modified'] );
-			}
-		}
-
-		if ($t_last_updated < $t_date_submitted) {
-			$t_last_updated   = 0;
-			$t_date_submitted = 0;
-		}
-
-		$t_diff = $t_last_updated - $t_date_submitted;
-		$t_total_time = $t_total_time + $t_diff;
-		if ( $t_diff > $t_largest_diff ) {
-			$t_largest_diff = $t_diff;
-			$t_bug_id = $row['id'];
-		}
-	}
-	if ( $bug_count < 1 ) {
-		$bug_count = 1;
-	}
-	$t_average_time 	= $t_total_time / $bug_count;
-
-	$t_largest_diff 	= number_format( $t_largest_diff / 86400, 2 );
-	$t_total_time		= number_format( $t_total_time / 86400, 2 );
-	$t_average_time 	= number_format( $t_average_time / 86400, 2 );
+	$t_time_stats = summary_get_time_stats();
 
 	$t_orct_arr = preg_split( '/[\)\/\(]/', lang_get( 'orct' ), -1, PREG_SPLIT_NO_EMPTY );
 
@@ -194,8 +137,8 @@
 			</td>
 			<td width="50%">
 				<?php
-					if ($t_bug_id>0) {
-						print_bug_link( $t_bug_id );
+					if ( $t_time_stats['longest_id'] > 0 ) {
+						print_bug_link( $t_time_stats['longest_id'] );
 					}
 				?>
 			</td>
@@ -205,7 +148,7 @@
 				<?php echo lang_get( 'longest_open' ) ?>
 			</td>
 			<td>
-				<?php echo $t_largest_diff ?>
+				<?php echo $t_time_stats['longest'] ?>
 			</td>
 		</tr>
 		<tr class="row-1">
@@ -213,7 +156,7 @@
 				<?php echo lang_get( 'average_time' ) ?>
 			</td>
 			<td>
-				<?php echo $t_average_time ?>
+				<?php echo $t_time_stats['average'] ?>
 			</td>
 		</tr>
 		<tr class="row-2">
@@ -221,7 +164,7 @@
 				<?php echo lang_get( 'total_time' ) ?>
 			</td>
 			<td>
-				<?php echo $t_total_time ?>
+				<?php echo $t_time_stats['total'] ?>
 			</td>
 		</tr>
 		</table>
Index: core/summary_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/summary_api.php,v
retrieving revision 1.39
diff -u -r1.39 summary_api.php
--- core/summary_api.php	22 Apr 2005 22:11:18 -0000	1.39
+++ core/summary_api.php	17 Jun 2005 13:15:19 -0000
@@ -922,4 +894,52 @@
 			}
 		}
 	}
+	
+		function summary_get_time_stats() {
+		$t_bug_table = config_get( 'mantis_bug_table' );
+		$t_history_table = config_get( 'mantis_bug_history_table' );
+		$t_specific_where = helper_project_specific_where( helper_get_current_project() );
+		$query = "SELECT mantis_bug_table.id as id,
+				(unix_timestamp(mantis_bug_history_table.date_modified)-unix_timestamp(mantis_bug_table.date_submitted)) as opentime
+				FROM $t_bug_table, $t_history_table
+				WHERE $t_specific_where
+				AND mantis_bug_table.id=mantis_bug_history_table.bug_id 
+				AND mantis_bug_history_table.field_name='status' 
+				AND mantis_bug_table.status>=80 
+				AND ((mantis_bug_history_table.new_value=80)
+				OR (mantis_bug_history_table.old_value<80 
+				AND mantis_bug_history_table.new_value=90)
+				)
+				ORDER BY mantis_bug_table.id"; 
+		$result = db_query( $query );
+		
+		$bug_count = db_num_rows( $result );
+		
+		$t_bug_id       = 0;
+		$t_largest_diff = 0;
+		$t_total_time   = 0;
+		for ($i=0;$i<$bug_count;$i++) {
+			$row = db_fetch_array( $result );
+			$t_diff = $row['opentime'];
+			
+			$t_total_time = $t_total_time + $t_diff;
+			if ( $t_diff > $t_largest_diff ) {
+				$t_largest_diff = $t_diff;
+				$t_bug_id = $row['id'];
+			}
+		}
+		if ( $bug_count < 1 ) {
+			$bug_count = 1;
+		}
+		$t_average_time 	= $t_total_time / $bug_count;
+		
+		$t_largest_diff 	= number_format( $t_largest_diff / 86400, 2 );
+		$t_total_time		= number_format( $t_total_time / 86400, 2 );
+		$t_average_time 	= number_format( $t_average_time / 86400, 2 );
+		return Array (
+			"average" => $t_average_time,
+			"total" => $t_total_time,
+			"longest" => $t_largest_diff,
+			"longest_id" => $t_bug_id );
+	}
 ?>
timestats.patch (5,954 bytes)   
grangeway

grangeway

2007-11-11 08:18

reporter   ~0016152

Hello,

I believe the issue you describe has already been fixed in the 1.1.X releases

If you are still having this issue with the 1.1.0 releases please let us know.

Thanks
Paul

Issue History

Date Modified Username Field Change
2005-06-17 09:31 Sjord New Issue
2005-06-17 09:31 Sjord File Added: timestats.patch
2005-06-17 14:42 thraxisp Status new => acknowledged
2005-06-17 14:42 thraxisp Relationship added child of 0004181
2007-11-11 08:18 grangeway Status acknowledged => resolved
2007-11-11 08:18 grangeway Resolution open => no change required
2007-11-11 08:18 grangeway Assigned To => grangeway
2007-11-11 08:18 grangeway Note Added: 0016152
2008-08-12 09:35 grangeway Status resolved => closed