From c87cfbc7b10a75645d82fdb8b50d0f4253f86bf8 Mon Sep 17 00:00:00 2001 From: call-me-matt Date: Sun, 2 Aug 2020 13:47:27 +0200 Subject: [PATCH] optimization: treat only contacts with social profile Signed-off-by: call-me-matt --- lib/Service/SocialApiService.php | 13 +++++++------ tests/unit/Service/SocialApiServiceTest.php | 11 +++-------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/Service/SocialApiService.php b/lib/Service/SocialApiService.php index 3660dec28..8a5cd5268 100644 --- a/lib/Service/SocialApiService.php +++ b/lib/Service/SocialApiService.php @@ -291,14 +291,15 @@ public function updateAddressbooks(string $network, string $userId) : JSONRespon if (is_null($addressBook)) { continue; } - // get contacts in that addressbook - $contacts = $addressBook->search('', ['UID'], ['types' => true]); - // TODO: filter for contacts with social profiles - if (is_null($contacts)) { - continue; + $contacts = $addressBook->search('', ['X-SOCIALPROFILE'], ['types' => true]); + if (empty($contacts)) { + // Fallback: X-SOCIALPROFILE not indexed? take all contacts: + $contacts = $addressBook->search('', ['UID'], ['types' => true]); + if (empty($contacts)) { + continue; + } } - // update one contact after another foreach ($contacts as $contact) { // delay to prevent rate limiting issues diff --git a/tests/unit/Service/SocialApiServiceTest.php b/tests/unit/Service/SocialApiServiceTest.php index 692d478b2..36aecbee6 100644 --- a/tests/unit/Service/SocialApiServiceTest.php +++ b/tests/unit/Service/SocialApiServiceTest.php @@ -187,11 +187,13 @@ protected function setupAddressbooks() { $searchMap1 = [ ['', ['UID'], ['types' => true], [$validContact1, $invalidContact]], + ['', ['X-SOCIALPROFILE'], ['types' => true], [$validContact1, $invalidContact]], [$validContact1['UID'], ['UID'], ['types' => true], [$validContact1]], [$invalidContact['UID'], ['UID'], ['types' => true], [$invalidContact]], ]; $searchMap2 = [ ['', ['UID'], ['types' => true], [$validContact2, $emptyContact]], + ['', ['X-SOCIALPROFILE'], ['types' => true], [$validContact2]], [$validContact2['UID'], ['UID'], ['types' => true], [$validContact2]], [$emptyContact['UID'], ['UID'], ['types' => true], [$emptyContact]], ]; @@ -230,13 +232,6 @@ protected function setupAddressbooks() { $invalidResponse ->method('getHeader') ->willReturn(''); - $response = $this->createMock(IResponse::class); - $response - ->method('getBody') - ->willReturn($httpResult); - $response - ->method('getHeader') - ->willReturn($httpResult); $clientResponseMap = [ ['validConnector', [], $validResponse], @@ -280,7 +275,7 @@ public function testUpdateAddressbooks($syncAllowedByAdmin, $bgSyncEnabledByUser $this->assertArrayHasKey('failed', $report[0]); $this->assertArrayHasKey('404', $report[0]['failed']); $this->assertContains('Invalid Contact', $report[0]['failed']['404']); - $this->assertContains('Empty Contact', $report[0]['failed']['404']); + $this->assertNotContains('Empty Contact', $report[0]['failed']['404']); } } }