1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-02-07 01:54:16 +01:00

Removed redundant DB queries.

This commit is contained in:
Thomas Tanghus 2011-12-31 01:34:22 +01:00
parent 6c8c89a57d
commit aa2fabaef9
2 changed files with 16 additions and 7 deletions

View File

@ -189,9 +189,21 @@ class OC_Contacts_Addressbook{
public static function active($uid){ public static function active($uid){
$active = self::activeIds($uid); $active = self::activeIds($uid);
$addressbooks = array(); $addressbooks = array();
/* FIXME: Is there a way to prepare a statement 'WHERE id IN ([range])'? $ids_sql = join(',', array_fill(0, count($active), '?'));
* See OC_Contacts_VCard:all. $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 ){ foreach( $active as $aid ){
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ? ORDER BY displayname' ); $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ? ORDER BY displayname' );
$result = $stmt->execute(array($aid,)); $result = $stmt->execute(array($aid,));
@ -199,7 +211,7 @@ class OC_Contacts_Addressbook{
while( $row = $result->fetchRow()){ while( $row = $result->fetchRow()){
$addressbooks[] = $row; $addressbooks[] = $row;
} }
} }*/
return $addressbooks; return $addressbooks;
} }

View File

@ -47,9 +47,6 @@ class OC_Contacts_VCard{
* ['carddata'] * ['carddata']
*/ */
public static function all($id){ 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)) { if(is_array($id)) {
$id_sql = join(',', array_fill(0, count($id), '?')); $id_sql = join(',', array_fill(0, count($id), '?'));
$prep = 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid IN ('.$id_sql.') ORDER BY fullname'; $prep = 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid IN ('.$id_sql.') ORDER BY fullname';