Changeset 385
- Timestamp:
- 09/06/12 15:58:43 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r384 r385 2464 2464 $args{sortby} = 'g2.group_name' if $args{sortby} eq 'parent'; 2465 2465 2466 my $sql = q(SELECT g.group_id AS groupid, g.group_name AS groupname, g2.group_name AS pgroup, 2467 count(distinct(u.username)) AS nusers, count(distinct(d.domain)) AS ndomains, 2468 count(distinct(r.revnet)) AS nrevzones 2466 my $sql = q(SELECT g.group_id AS groupid, g.group_name AS groupname, g2.group_name AS pgroup 2469 2467 FROM groups g 2470 2468 INNER JOIN groups g2 ON g2.group_id=g.parent_group_id 2471 LEFT OUTER JOIN users u ON u.group_id=g.group_id2472 LEFT OUTER JOIN domains d ON d.group_id=g.group_id2473 LEFT OUTER JOIN revzones r ON r.group_id=g.group_id2474 2469 ). 2475 " WHERE g.parent_group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".2470 " WHERE g.parent_group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")". 2476 2471 ($args{startwith} ? " AND g.group_name ~* ?" : ''). 2477 2472 ($args{filter} ? " AND g.group_name ~* ?" : ''). … … 2481 2476 my $glist = $dbh->selectall_arrayref($sql, { Slice => {} }, (@filterargs) ); 2482 2477 $errstr = $dbh->errstr if !$glist; 2478 2479 # LEFT JOINs make the result set balloon beyond sanity just to include counts; 2480 # this means there's lots of crunching needed to trim the result set back down. 2481 # So instead we track the order of the groups, and push the counts into the 2482 # arrayref result separately. 2483 ##fixme: put this whole sub in a transaction? might be 2484 # needed for accurate results on very busy systems. 2485 my %gref; 2486 my $i = 0; 2487 foreach (@{$glist}) { 2488 $gref{$$_{groupid}} = $i++; 2489 } 2490 my $tmpchlist = $args{curgroup}.($args{childlist} ? ",$args{childlist}" : ''); 2491 foreach my $grp (split /,/, $tmpchlist) { 2492 my ($ucnt) = $dbh->selectrow_array("SELECT count(*) FROM users WHERE group_id=?", undef, ($grp)); 2493 $glist->[$gref{$grp}]{nusers} = $ucnt; 2494 my ($dcnt) = $dbh->selectrow_array("SELECT count(*) FROM domains WHERE group_id=?", undef, ($grp)); 2495 $glist->[$gref{$grp}]{ndomains} = $dcnt; 2496 my ($rcnt) = $dbh->selectrow_array("SELECT count(*) FROM revzones WHERE group_id=?", undef, ($grp)); 2497 $glist->[$gref{$grp}]{nrevzones} = $rcnt; 2498 } 2499 2483 2500 return $glist; 2484 2501 } # end getGroupList
Note:
See TracChangeset
for help on using the changeset viewer.