From 73627e594d61e4606b57880cb35bdc50efb3e900 Mon Sep 17 00:00:00 2001 From: "terry%mozilla.org" <> Date: Tue, 12 Oct 1999 00:14:30 +0000 Subject: Added a "votes" field to the bugs table, which caches the total number of votes that have been cast for that bug. This let me simplify the SQL in buglist.cgi, which makes things more efficient and fixes several strange bugs. --- sanitycheck.cgi | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 5 deletions(-) (limited to 'sanitycheck.cgi') diff --git a/sanitycheck.cgi b/sanitycheck.cgi index f13fb4a13..b1b2022eb 100755 --- a/sanitycheck.cgi +++ b/sanitycheck.cgi @@ -24,11 +24,14 @@ use strict; require "CGI.pl"; +use vars %::FORM; + print "Content-type: text/html\n"; print "\n"; ConnectToDatabase(); +my $offervotecacherebuild = 0; sub Status { my ($str) = (@_); @@ -45,14 +48,37 @@ sub BugLink { return "$id"; } +sub AlertBadVoteCache { + my ($id) = (@_); + Alert("Bad vote cache for bug " . BugLink($id)); + $offervotecacherebuild = 1; +} -PutHeader("Bugzilla Sanity Check"); - -print "OK, now running sanity checks.

\n"; my @row; my @checklist; +PutHeader("Bugzilla Sanity Check"); + +if (exists $::FORM{'rebuildvotecache'}) { + Status("OK, now rebuilding vote cache."); + SendSQL("lock tables bugs write, votes read"); + SendSQL("update bugs set votes = 0"); + SendSQL("select bug_id, sum(count) from votes group by bug_id"); + my %votes; + while (@row = FetchSQLData()) { + my ($id, $v) = (@row); + $votes{$id} = $v; + } + foreach my $id (keys %votes) { + SendSQL("update bugs set votes = $votes{$id} where bug_id = $id"); + } + SendSQL("unlock tables"); + Status("Vote cache has been rebuild."); +} + +print "OK, now running sanity checks.

\n"; + Status("Checking groups"); SendSQL("select bit from groups where bit != pow(2, round(log(bit) / log(2)))"); while (my $bit = FetchOneColumn()) { @@ -124,12 +150,13 @@ undef $profid{0}; Status("Checking reporter/assigned_to/qa_contact ids"); -SendSQL("select bug_id,reporter,assigned_to,qa_contact from bugs"); +SendSQL("select bug_id,reporter,assigned_to,qa_contact,votes from bugs"); +my %votes; my %bugid; while (@row = FetchSQLData()) { - my($id, $reporter, $assigned_to, $qa_contact) = (@row); + my($id, $reporter, $assigned_to, $qa_contact, $v) = (@row); $bugid{$id} = 1; if (!defined $profid{$reporter}) { Alert("Bad reporter $reporter in " . BugLink($id)); @@ -140,8 +167,34 @@ while (@row = FetchSQLData()) { if ($qa_contact != 0 && !defined $profid{$qa_contact}) { Alert("Bad qa_contact $qa_contact in" . BugLink($id)); } + if ($v != 0) { + $votes{$id} = $v; + } +} + +Status("Checking cached vote counts"); +SendSQL("select bug_id, sum(count) from votes group by bug_id"); + +while (@row = FetchSQLData()) { + my ($id, $v) = (@row); + if ($v <= 0) { + Alert("Bad vote sum for bug $id"); + } else { + if (!defined $votes{$id} || $votes{$id} != $v) { + AlertBadVoteCache($id); + } + delete $votes{$id}; + } +} +foreach my $id (keys %votes) { + AlertBadVoteCache($id); } +if ($offervotecacherebuild) { + print qq{Click here to rebuild the vote cache

\n}; +} + + Status("Checking CC table"); SendSQL("select bug_id,who from cc"); -- cgit v1.2.3-24-g4f1b