Fixed DCM-2074: Enhanced query performance
authorhs321.lee <hs321.lee@samsung.com>
Mon, 24 Jun 2013 04:33:28 +0000 (13:33 +0900)
committerhs321.lee <hs321.lee@samsung.com>
Mon, 24 Jun 2013 04:33:34 +0000 (13:33 +0900)
Change-Id: Ie7b949e3fb1273aa9fb12d15fdb4115adb85a429
Signed-off-by: hs321.lee <hs321.lee@samsung.com>
src/FScl_AddressbookUtil.cpp
src/FScl_AddressbookUtil.h

index 195c59d..aba153d 100644 (file)
@@ -915,4 +915,40 @@ _AddressbookUtil::GetRwAbIdListN(void)
        return pAbIdList.release();
 }
 
+result
+_AddressbookUtil::GetAbListN(IListT<AddressbookId>& rwAbIdList, IListT<AddressbookId>& roAbIdList)
+{
+       ClearLastResult();
+
+       __Query<__ContactsAddressbook> query;
+       query.Construct();
+
+       std::unique_ptr<__SearchResult<__ContactsAddressbook> > pSearchResult(_AddressbookUtil::ExecuteQuery(query, 0, 0));
+       if (pSearchResult == null)
+       {
+               return E_SUCCESS;
+       }
+
+       while (pSearchResult->MoveNext() == E_SUCCESS)
+       {
+               int intValue = 0;
+               contacts_record_h currentRecord = pSearchResult->GetCurrentRecord();
+
+               contacts_record_get_int(currentRecord, _contacts_address_book.mode, &intValue);
+               if (intValue == CONTACTS_ADDRESS_BOOK_MODE_NONE)
+               {
+                       contacts_record_get_int(currentRecord, _contacts_address_book.id, &intValue);
+
+                       rwAbIdList.Add(intValue);
+               }
+               else
+               {
+                       contacts_record_get_int(currentRecord, _contacts_address_book.id, &intValue);
+                       roAbIdList.Add(intValue);
+               }
+       }
+
+       return E_SUCCESS;
+}
+
 }}  // Tizen::Social
index f75309f..d2e53d2 100644 (file)
@@ -850,44 +850,68 @@ public:
        static Tizen::Base::Collection::IListT<AddressbookId>* GetRwAbIdListN(void);
        static Tizen::Base::Collection::IListT<AddressbookId>* GetRoAbIdListN(void);
 
+       static result GetAbListN(Tizen::Base::Collection::IListT<AddressbookId>& rwAbIdList, Tizen::Base::Collection::IListT<AddressbookId>& roAbIdList);
+
        template<typename __View>
        static __Filter<__View>* GetRwAbFilterN(void)
        {
-               std::unique_ptr< Tizen::Base::Collection::IListT<AddressbookId> > pAbIdList(GetRwAbIdListN());
-               SysTryReturn(NID_SCL, pAbIdList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
                std::unique_ptr< __Filter<__View> > pFilter(new (std::nothrow) __Filter<__View>);
                SysTryReturn(NID_SCL, pFilter != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
+               Tizen::Base::Collection::ArrayListT<AddressbookId> rwAbIdList;
+               rwAbIdList.Construct();
+
+               Tizen::Base::Collection::ArrayListT<AddressbookId> roAbIdList;
+               roAbIdList.Construct();
+
+               GetAbListN(rwAbIdList, roAbIdList);
+
+               if (roAbIdList.GetCount() == 0)
+               {
+                       // return null filter
+                       return pFilter.release();
+               }       
+
                pFilter->Construct();
 
                bool isFirst = true;
                AddressbookId addressbookId = -1;
 
-               std::unique_ptr< Tizen::Base::Collection::IEnumeratorT<AddressbookId> > pEnum(pAbIdList->GetEnumeratorN());
-
-               if (pAbIdList->GetCount() > 0)
+               if (rwAbIdList.GetCount() < 5)
                {
+                       std::unique_ptr< Tizen::Base::Collection::IEnumeratorT<AddressbookId> > pEnum(rwAbIdList.GetEnumeratorN());
                        while (pEnum->MoveNext() == E_SUCCESS)
                        {
                                pEnum->GetCurrent(addressbookId);
                                if (!isFirst)
                                {
-                                       pFilter->AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                                       pFilter->AddOperator(CONTACTS_FILTER_OPERATOR_OR);
                                }
                                else
                                {
                                        isFirst = false;
                                }
 
-                               pFilter->AddInt(__View::GetAbPropertyId(), CONTACTS_MATCH_NOT_EQUAL, addressbookId);
+                               pFilter->AddInt(__View::GetAbPropertyId(), CONTACTS_MATCH_EQUAL, addressbookId);
                        }
                }
                else
                {
-                               pFilter->AddInt(__View::GetAbPropertyId(), CONTACTS_MATCH_NOT_EQUAL, 2);
-                               pFilter->AddOperator(CONTACTS_FILTER_OPERATOR_AND);
-                               pFilter->AddInt(__View::GetAbPropertyId(), CONTACTS_MATCH_NOT_EQUAL, 3);
+                       std::unique_ptr< Tizen::Base::Collection::IEnumeratorT<AddressbookId> > pEnum(roAbIdList.GetEnumeratorN());
+                       while (pEnum->MoveNext() == E_SUCCESS)
+                       {
+                               pEnum->GetCurrent(addressbookId);
+                               if (!isFirst)
+                               {
+                                       pFilter->AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                               }
+                               else
+                               {
+                                       isFirst = false;
+                               }
+
+                               pFilter->AddInt(__View::GetAbPropertyId(), CONTACTS_MATCH_NOT_EQUAL, addressbookId);
+                       }
                }
 
                return pFilter.release();