Index: trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
===================================================================
--- trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 20966)
+++ trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 20990)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.77 2008-12-12 21:41:07 jhoblitt Exp $
+# $Id: SQL.pm,v 1.78 2008-12-14 22:54:25 eugene Exp $
 
 package Nebulous::Server::SQL;
@@ -8,5 +8,5 @@
 use warnings FATAL => qw( all );
 
-our $VERSION = '0.03';
+our $VERSION = '0.02';
 
 use base qw( Class::Accessor::Fast );
@@ -47,8 +47,4 @@
         (so_id, vol_id, uri)
         VALUES (?, ?, 'error')
-    },
-    get_all_instances   => qq{
-        SELECT * FROM INSTANCE
-        WHERE so_id = ?
     },
     get_object          => qq{
@@ -328,26 +324,28 @@
         HAVING available_instances < instances OR instances < copies
     },
-    find_objects_with_extra_instances_by_xattr => qq{
-        SELECT
-            so.so_id,
-            so.ext_id,
+    find_objects_with_extra_instances => qq{
+        SELECT
+            storage_object.so_id,
+            ext_id,
             count(ins_id) as instances,
-            mv.name as volume_name,
-            mv.host as volume_host,
-            count(mv.vol_id) as available_instances,
-            xattr.value as copies
-        FROM storage_object AS so
-        JOIN storage_object_xattr as xattr
-            ON so.so_id = xattr.so_id
-            AND xattr.name = 'user.copies'
-        JOIN instance AS i
-            ON so.so_id = i.so_id
-        JOIN mountedvol AS mv
+            volume.name as volume_name,
+            volume.host as volume_host,
+            count(mymountedvol.vol_id) as available_instances,
+            count(mymountedvol.vol_id) > 0 as recoverable,
+            storage_object_xattr.value as copies
+        FROM storage_object
+        JOIN instance
+            USING(so_id)
+        JOIN volume
+            USING(vol_id)
+        LEFT JOIN storage_object_xattr
+            ON storage_object.so_id = storage_object_xattr.so_id
+        JOIN mymountedvol
             USING(vol_id)
         WHERE
-            mv.available = 1
+            mymountedvol.available = 1
+            AND storage_object_xattr.name = 'user.copies'
         GROUP BY so_id
         HAVING available_instances > copies
-        limit 5;
     },
     get_mounted_volumes => qq{
