]> source.dussan.org Git - nextcloud-server.git/commitdiff
feat: configurable request timeout for carddav sync
authorPablo Zmdl <pablo@nextcloud.com>
Fri, 27 Sep 2024 11:59:09 +0000 (13:59 +0200)
committerDaniel <mail@danielkesselberg.de>
Thu, 17 Oct 2024 20:27:10 +0000 (22:27 +0200)
Big federated setups may need a longer timeout, which they now can
configure.

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
Co-authored-by: Josh <josh.t.richards@gmail.com>
apps/dav/lib/CardDAV/SyncService.php
apps/dav/tests/unit/CardDAV/SyncServiceTest.php
config/config.sample.php

index 05a08d08286baa03728dd3dd05cface56acdaa9b..026a02a72ab2658dcf91fa84023ac9c3f6b2de36 100644 (file)
@@ -11,6 +11,7 @@ namespace OCA\DAV\CardDAV;
 use OCP\AppFramework\Db\TTransactional;
 use OCP\AppFramework\Http;
 use OCP\Http\Client\IClientService;
+use OCP\IConfig;
 use OCP\IDBConnection;
 use OCP\IUser;
 use OCP\IUserManager;
@@ -33,13 +34,15 @@ class SyncService {
        private Converter $converter;
        protected string $certPath;
        private IClientService $clientService;
+       private IConfig $config;
 
        public function __construct(CardDavBackend $backend,
                IUserManager $userManager,
                IDBConnection $dbConnection,
                LoggerInterface $logger,
                Converter $converter,
-               IClientService $clientService) {
+               IClientService $clientService,
+               IConfig $config) {
                $this->backend = $backend;
                $this->userManager = $userManager;
                $this->logger = $logger;
@@ -47,6 +50,7 @@ class SyncService {
                $this->certPath = '';
                $this->dbConnection = $dbConnection;
                $this->clientService = $clientService;
+               $this->config = $config;
        }
 
        /**
@@ -150,7 +154,8 @@ class SyncService {
                $options = [
                        'auth' => [$userName, $sharedSecret],
                        'body' => $this->buildSyncCollectionRequestBody($syncToken),
-                       'headers' => ['Content-Type' => 'application/xml']
+                       'headers' => ['Content-Type' => 'application/xml'],
+                       'timeout' => $this->config->getSystemValueInt('carddav_sync_request_timeout', 30)
                ];
 
                $response = $client->request(
index db99f73306d2623713c9eacd566d3c2d0153d13d..5af42e2ea4ec9de801c8a950074ae12764e9ffca 100644 (file)
@@ -16,6 +16,7 @@ use OCA\DAV\CardDAV\Converter;
 use OCA\DAV\CardDAV\SyncService;
 use OCP\Http\Client\IClient;
 use OCP\Http\Client\IClientService;
+use OCP\IConfig;
 use OCP\IDBConnection;
 use OCP\IUser;
 use OCP\IUserManager;
@@ -33,6 +34,7 @@ class SyncServiceTest extends TestCase {
        protected LoggerInterface $logger;
        protected Converter $converter;
        protected IClient $client;
+       protected IConfig $config;
        protected SyncService $service;
        public function setUp(): void {
                $addressBook = [
@@ -53,6 +55,7 @@ class SyncServiceTest extends TestCase {
                $this->logger = new NullLogger();
                $this->converter = $this->createMock(Converter::class);
                $this->client = $this->createMock(IClient::class);
+               $this->config = $this->createMock(IConfig::class);
 
                $clientService = $this->createMock(IClientService::class);
                $clientService->method('newClient')
@@ -64,7 +67,8 @@ class SyncServiceTest extends TestCase {
                        $this->dbConnection,
                        $this->logger,
                        $this->converter,
-                       $clientService
+                       $clientService,
+                       $this->config
                );
        }
 
@@ -305,8 +309,9 @@ END:VCARD';
                $logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
                $converter = $this->createMock(Converter::class);
                $clientService = $this->createMock(IClientService::class);
+               $config = $this->createMock(IConfig::class);
 
-               $ss = new SyncService($backend, $userManager, $dbConnection, $logger, $converter, $clientService);
+               $ss = new SyncService($backend, $userManager, $dbConnection, $logger, $converter, $clientService, $config);
                $ss->ensureSystemAddressBookExists('principals/users/adam', 'contacts', []);
        }
 
@@ -360,8 +365,9 @@ END:VCARD';
                        ->willReturn($this->createMock(VCard::class));
 
                $clientService = $this->createMock(IClientService::class);
+               $config = $this->createMock(IConfig::class);
 
-               $ss = new SyncService($backend, $userManager, $dbConnection, $logger, $converter, $clientService);
+               $ss = new SyncService($backend, $userManager, $dbConnection, $logger, $converter, $clientService, $config);
                $ss->updateUser($user);
 
                $ss->updateUser($user);
index 21a77a8cbf64677957483ab7b2c4a3c3893b6027..709c1fb73c63a8a8033e45c6655530e875b6bf0d 100644 (file)
@@ -340,6 +340,13 @@ $CONFIG = [
  */
 'davstorage.request_timeout' => 30,
 
+/**
+ * The timeout in seconds for synchronizing address books, e.g. federated system address books (as run by `occ federation:sync-addressbooks`).
+ * 
+ * Defaults to ``30`` seconds
+ */
+'carddav_sync_request_timeout' => 30,
+
 /**
  * `true` enabled a relaxed session timeout, where the session timeout would no longer be
  * handled by Nextcloud but by either the PHP garbage collection or the expiration of