From 2432e924dab2cb5ba394b3b321fcb34841656134 Mon Sep 17 00:00:00 2001 From: Wolfgang Lubowski Date: Wed, 22 Apr 2026 21:04:03 +0200 Subject: [PATCH 1/2] feat(preview-enhancement): make background-job interval configurable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PreviewEnhancementProcessingJob is what writes the `imip_message` flag onto mail_messages rows. Downstream, IMipMessageJob only picks up messages with that flag set, so the enhancement interval is the ceiling on how long an incoming calendar invitation can take to turn into a CalDAV event. The current hard-coded 3600s is reasonable for bulk-preview enrichment but way too slow for the iMIP pipeline: small Proton/Fastmail/self- hosted installs that want invitations to feel live need something in the 60–300s range. That's a per-setup trade-off (smaller sites have the headroom, larger ones probably do not), so let's expose the knob instead of picking one number. New system config: occ config:system:set app.mail.preview-enhancement-interval \ --value=300 --type=integer When unset, keeps the existing 3600s default. A MIN_INTERVAL=60s floor prevents a misconfigured value from hammering the DB. The job instance is re-created every time the scheduler enqueues it, so the new value takes effect on the next tick — no restart needed. AI-assisted: Claude Code (Claude Opus 4.7) Signed-off-by: Wolfgang Lubowski --- .../PreviewEnhancementProcessingJob.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/BackgroundJob/PreviewEnhancementProcessingJob.php b/lib/BackgroundJob/PreviewEnhancementProcessingJob.php index d5a60d6b95..ad685413be 100644 --- a/lib/BackgroundJob/PreviewEnhancementProcessingJob.php +++ b/lib/BackgroundJob/PreviewEnhancementProcessingJob.php @@ -14,11 +14,16 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\TimedJob; +use OCP\IConfig; use OCP\IUserManager; use Psr\Log\LoggerInterface; +use function max; use function sprintf; class PreviewEnhancementProcessingJob extends TimedJob { + private const DEFAULT_INTERVAL = 3600; + private const MIN_INTERVAL = 60; + private IUserManager $userManager; private AccountService $accountService; private LoggerInterface $logger; @@ -30,7 +35,8 @@ public function __construct(ITimeFactory $time, AccountService $accountService, PreprocessingService $preprocessingService, LoggerInterface $logger, - IJobList $jobList) { + IJobList $jobList, + IConfig $config) { parent::__construct($time); $this->userManager = $userManager; @@ -39,7 +45,16 @@ public function __construct(ITimeFactory $time, $this->jobList = $jobList; $this->preprocessingService = $preprocessingService; - $this->setInterval(3600); + // Allow admins to tighten the interval on setups where preview data + // directly gates user-visible behaviour (e.g. the imip_message flag + // that IMipMessageJob depends on to turn incoming invitations into + // calendar events). A floor of MIN_INTERVAL keeps a misconfigured + // value from hammering the DB. + $configured = $config->getSystemValueInt( + 'app.mail.preview-enhancement-interval', + self::DEFAULT_INTERVAL, + ); + $this->setInterval(max(self::MIN_INTERVAL, $configured)); $this->setTimeSensitivity(self::TIME_SENSITIVE); } From 1cbb893f2fc42e381288771780b65b860356c43b Mon Sep 17 00:00:00 2001 From: Wolfgang Lubowski Date: Wed, 13 May 2026 13:26:15 +0200 Subject: [PATCH 2/2] fixup! feat(preview-enhancement): make background-job interval configurable Address review feedback: - switch to IAppConfig (getValueInt) instead of IConfig getSystemValueInt - rename key to preview_enhancement_interval (no dots, AntiSpamService style) - expose CONFIG_KEY_INTERVAL constant for symmetry with other services - update unit test to mock IAppConfig and pass through default NOTE for squash: original commit body still references the old occ config:system:set example. When squashing, please update the example to: occ config:app:set mail preview_enhancement_interval --value=300 --type=integer AI-assisted: Claude Code (Claude Opus 4.7) Signed-off-by: Wolfgang Lubowski --- lib/BackgroundJob/PreviewEnhancementProcessingJob.php | 11 +++++++---- .../Unit/Job/PreviewEnhancementProcessingJobTest.php | 10 +++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/BackgroundJob/PreviewEnhancementProcessingJob.php b/lib/BackgroundJob/PreviewEnhancementProcessingJob.php index ad685413be..11edcf3419 100644 --- a/lib/BackgroundJob/PreviewEnhancementProcessingJob.php +++ b/lib/BackgroundJob/PreviewEnhancementProcessingJob.php @@ -8,19 +8,21 @@ namespace OCA\Mail\BackgroundJob; +use OCA\Mail\AppInfo\Application; use OCA\Mail\Service\AccountService; use OCA\Mail\Service\PreprocessingService; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\TimedJob; -use OCP\IConfig; +use OCP\IAppConfig; use OCP\IUserManager; use Psr\Log\LoggerInterface; use function max; use function sprintf; class PreviewEnhancementProcessingJob extends TimedJob { + public const CONFIG_KEY_INTERVAL = 'preview_enhancement_interval'; private const DEFAULT_INTERVAL = 3600; private const MIN_INTERVAL = 60; @@ -36,7 +38,7 @@ public function __construct(ITimeFactory $time, PreprocessingService $preprocessingService, LoggerInterface $logger, IJobList $jobList, - IConfig $config) { + IAppConfig $appConfig) { parent::__construct($time); $this->userManager = $userManager; @@ -50,8 +52,9 @@ public function __construct(ITimeFactory $time, // that IMipMessageJob depends on to turn incoming invitations into // calendar events). A floor of MIN_INTERVAL keeps a misconfigured // value from hammering the DB. - $configured = $config->getSystemValueInt( - 'app.mail.preview-enhancement-interval', + $configured = $appConfig->getValueInt( + Application::APP_ID, + self::CONFIG_KEY_INTERVAL, self::DEFAULT_INTERVAL, ); $this->setInterval(max(self::MIN_INTERVAL, $configured)); diff --git a/tests/Unit/Job/PreviewEnhancementProcessingJobTest.php b/tests/Unit/Job/PreviewEnhancementProcessingJobTest.php index 96b7c3c65a..0263e9ab8f 100644 --- a/tests/Unit/Job/PreviewEnhancementProcessingJobTest.php +++ b/tests/Unit/Job/PreviewEnhancementProcessingJobTest.php @@ -15,6 +15,7 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; +use OCP\IAppConfig; use OCP\IUser; use OCP\IUserManager; use Psr\Log\LoggerInterface; @@ -37,6 +38,9 @@ class PreviewEnhancementProcessingJobTest extends TestCase { /** @var IJobList|IJobList&MockObject|MockObject */ private $jobList; + + /** @var IAppConfig|IAppConfig&MockObject|MockObject */ + private $appConfig; private PreviewEnhancementProcessingJob $job; /** @var int[] */ @@ -50,13 +54,17 @@ public function setUp(): void { $this->preprocessingService = $this->createMock(PreprocessingService::class); $this->logger = $this->createMock(LoggerInterface::class); $this->jobList = $this->createMock(IJobList::class); + $this->appConfig = $this->createMock(IAppConfig::class); + $this->appConfig->method('getValueInt') + ->willReturnArgument(2); $this->job = new PreviewEnhancementProcessingJob( $this->time, $this->manager, $this->accountService, $this->preprocessingService, $this->logger, - $this->jobList + $this->jobList, + $this->appConfig, ); self::$argument = ['accountId' => 1];