Skip to content

Commit

Permalink
optimization: treat only contacts with social profile
Browse files Browse the repository at this point in the history
Signed-off-by: call-me-matt <nextcloud@matthiasheinisch.de>
  • Loading branch information
call-me-matt committed Aug 2, 2020
1 parent fdacb31 commit c87cfbc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
13 changes: 7 additions & 6 deletions lib/Service/SocialApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions tests/unit/Service/SocialApiServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
];
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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']);
}
}
}

0 comments on commit c87cfbc

Please sign in to comment.