Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lib/BackgroundJob/PreviewEnhancementProcessingJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@

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\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;

private IUserManager $userManager;
private AccountService $accountService;
private LoggerInterface $logger;
Expand All @@ -30,7 +37,8 @@ public function __construct(ITimeFactory $time,
AccountService $accountService,
PreprocessingService $preprocessingService,
LoggerInterface $logger,
IJobList $jobList) {
IJobList $jobList,
IAppConfig $appConfig) {
parent::__construct($time);

$this->userManager = $userManager;
Expand All @@ -39,7 +47,17 @@ 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 = $appConfig->getValueInt(
Application::APP_ID,
self::CONFIG_KEY_INTERVAL,
self::DEFAULT_INTERVAL,
);
$this->setInterval(max(self::MIN_INTERVAL, $configured));
$this->setTimeSensitivity(self::TIME_SENSITIVE);
}

Expand Down
10 changes: 9 additions & 1 deletion tests/Unit/Job/PreviewEnhancementProcessingJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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[] */
Expand All @@ -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];
Expand Down