]> source.dussan.org Git - nextcloud-server.git/commitdiff
Removed redundant DB queries.
authorThomas Tanghus <thomas@tanghus.net>
Sat, 31 Dec 2011 00:34:22 +0000 (01:34 +0100)
committerThomas Tanghus <thomas@tanghus.net>
Sat, 31 Dec 2011 00:34:22 +0000 (01:34 +0100)
apps/contacts/lib/addressbook.php
apps/contacts/lib/vcard.php

index b3c981a541e9acb43908ff3bdc40184b59a33bd2..78792f5f9482329f6f22117ee4f49cde1ab9ecce 100644 (file)
@@ -189,9 +189,21 @@ class OC_Contacts_Addressbook{
        public static function active($uid){
                $active = self::activeIds($uid);
                $addressbooks = array();
-               /* FIXME: Is there a way to prepare a statement 'WHERE id IN ([range])'?
-                * See OC_Contacts_VCard:all.
-               */
+               $ids_sql = join(',', array_fill(0, count($active), '?'));
+               $prep = 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id IN ('.$ids_sql.') ORDER BY displayname';
+               try {
+                       $stmt = OC_DB::prepare( $prep );
+                       $result = $stmt->execute($active);
+               } catch(Exception $e) {
+                       OC_Log::write('contacts','OC_Contacts_Addressbook:active:, exception: '.$e->getMessage(),OC_Log::DEBUG);
+                       OC_Log::write('contacts','OC_Contacts_Addressbook:active, ids: '.join(',', $active),OC_Log::DEBUG);
+                       OC_Log::write('contacts','OC_Contacts_Addressbook::active, SQL:'.$prep,OC_Log::DEBUG);
+               }
+
+               while( $row = $result->fetchRow()){
+                       $addressbooks[] = $row;
+               }
+               /*
                foreach( $active as $aid ){
                        $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ? ORDER BY displayname' );
                        $result = $stmt->execute(array($aid,));
@@ -199,7 +211,7 @@ class OC_Contacts_Addressbook{
                        while( $row = $result->fetchRow()){
                                $addressbooks[] = $row;
                        }
-               }
+               }*/
 
                return $addressbooks;
        }
index 81519b3d051842b9b163250a0edf4f1fa1c42b64..beb291b481e0d3661adb4ebb85434f6380f1d761 100644 (file)
@@ -47,9 +47,6 @@ class OC_Contacts_VCard{
         * ['carddata']
         */
        public static function all($id){
-               //$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? ORDER BY fullname' );
-               //$result = $stmt->execute(array($id));
-
                if(is_array($id)) {
                        $id_sql = join(',', array_fill(0, count($id), '?'));
                        $prep = 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid IN ('.$id_sql.') ORDER BY fullname';