From 36b5abf1b6afc8b04c2481eef8c471b2e5540dd9 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 | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Service/SocialApiService.php b/lib/Service/SocialApiService.php index 3660dec28..ed4edfdc6 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-SOCIALPROFILED 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..21ac558c3 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]], ]; @@ -280,7 +282,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']); } } }