[vhffs-dev] [1222] Better if we do a reverse order...

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1222
Author:   beuss
Date:     2008-06-06 13:22:51 +0200 (Fri, 06 Jun 2008)

Log Message:
-----------
Better if we do a reverse order...

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Group.pm


Modified: trunk/vhffs-api/src/Vhffs/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Group.pm	2008-06-06 11:00:00 UTC (rev 1221)
+++ trunk/vhffs-api/src/Vhffs/Group.pm	2008-06-06 11:22:51 UTC (rev 1222)
@@ -517,32 +517,24 @@
 
 }
 
-sub getall_quotalimit
-{
-        my $vhffs = shift;
-	my $limit = shift;
-	$limit = 10 if(! defined $limit );
-        my $db = $vhffs->get_db_object;
-        my @result;
-        my $query = 'SELECT groupname FROM vhffs_groups g LEFT JOIN vhffs_users u ON g.groupname = u.username WHERE g.quota_used >= 0.9 * g.quota AND u.uid IS NULL ORDER BY g.quota_used LIMIT ?';
-
-        my $request = $db->prepare( $query );
-        my $rows = $request->execute($limit);
-
-        return undef if( $rows <= 0 );
-
-        my $names = $request->fetchall_arrayref;
-
-        my $group;
-        foreach my $name ( @{$names} )
-        {
-                $group = Vhffs::Group::get_by_groupname( $vhffs , $name->[0] );
-                push( @result , $group) if( defined $group );
+sub getall_quotalimit {
+    my ($vhffs, $limit) = @_;
+    $limit = 10 unless(defined $limit);
+    my $sql = q{SELECT g.gid, o.object_id, o.owner_uid, g.groupname, g.realname, g.passwd, g.quota,
+    	g.quota_used, o.date_creation, o.description, o.state
+    	FROM vhffs_groups g INNER JOIN vhffs_object o ON o.object_id = g.object_id
+    	WHERE (g.quota_used / g.quota) >= 0.9 ORDER BY g.quota_used DESC LIMIT ?};
+    
+    my $dbh = $vhffs->get_db_object;
+    my $sth = $dbh->prepare($sql);
+    $sth->execute($limit) or return undef;
+    my $groups = [];
+    while(my @r = $sth->fetchrow_array) {
+    	push @{$groups}, _new Vhffs::Group($vhffs, @r);
     }
-    return \@result;
+    return $groups;
 }
 
-
 # Get all objects of the group
 sub getall_objects
 {


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/