Skip to content

Commit 0e5f2e5

Browse files
committed
refactor: Process all fs events asynchronously
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent d6e4f25 commit 0e5f2e5

12 files changed

Lines changed: 942 additions & 397 deletions

lib/BackgroundJobs/ProcessAccessUpdatesJob.php

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) 2021-2022 The Recognize contributors.
5+
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
6+
*/
7+
declare(strict_types=1);
8+
namespace OCA\Recognize\BackgroundJobs;
9+
10+
use OCA\Recognize\Db\FsActionMapper;
11+
use OCA\Recognize\Service\FsActionService;
12+
use OCP\AppFramework\Utility\ITimeFactory;
13+
use OCP\BackgroundJob\IJobList;
14+
use OCP\BackgroundJob\TimedJob;
15+
use OCP\DB\Exception;
16+
use Psr\Log\LoggerInterface;
17+
18+
final class ProcessFsActionsJob extends TimedJob {
19+
20+
public function __construct(
21+
ITimeFactory $timeFactory,
22+
private FsActionService $accessUpdateService,
23+
private IJobList $jobList,
24+
private FsActionMapper $accessUpdateMapper,
25+
private LoggerInterface $logger,
26+
) {
27+
parent::__construct($timeFactory);
28+
$this->setInterval(5 * 60);
29+
$this->setTimeSensitivity(self::TIME_SENSITIVE);
30+
}
31+
32+
/**
33+
* @param array{storage_id:int, type: string} $argument
34+
* @return void
35+
*/
36+
protected function run($argument): void {
37+
$storageId = $argument['storage_id'] ?? null;
38+
$className = $argument['type'];
39+
40+
if (isset($storageId)) {
41+
$this->accessUpdateService->processActionsByClassAndStorageId($className, $storageId);
42+
try {
43+
$remainingCount = $this->accessUpdateMapper->countByStorageId($className, $storageId);
44+
} catch (Exception $e) {
45+
$this->logger->error('Failed to count fs actions: ' . $e->getMessage(), ['exception' => $e]);
46+
$remainingCount = 1;
47+
}
48+
} else {
49+
$this->accessUpdateService->processActionsByClass($className);
50+
try {
51+
$remainingCount = $this->accessUpdateMapper->count($className);
52+
} catch (Exception $e) {
53+
$this->logger->error('Failed to count fs actions: ' . $e->getMessage(), ['exception' => $e]);
54+
$remainingCount = 1;
55+
}
56+
}
57+
58+
59+
if ($remainingCount === 0) {
60+
// Remove job from queue
61+
$this->jobList->remove(self::class, $argument);
62+
}
63+
}
64+
}

lib/Db/AccessUpdateMapper.php

Lines changed: 0 additions & 105 deletions
This file was deleted.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
use OCP\AppFramework\Db\Entity;
1111

1212
/**
13-
* Class AccessUpdate
13+
* Class FsAccessUpdate
1414
*
1515
* @package OCA\Recognize\Db
1616
* @method int getStorageId()
1717
* @method setStorageId(int $storageId)
1818
* @method int getRootId()
1919
* @method setRootId(int $rootId)
2020
*/
21-
final class AccessUpdate extends Entity {
21+
final class FsAccessUpdate extends Entity {
2222
protected ?int $storageId = null;
2323
protected ?int $rootId = null;
2424

@@ -32,6 +32,8 @@ final class AccessUpdate extends Entity {
3232
*/
3333
public static array $fields = ['id', 'storageId', 'rootId'];
3434

35+
public static string $tableName = 'recognize_fs_access_updates';
36+
3537
public function __construct() {
3638
// add types in constructor
3739
$this->addType('id', 'integer');

0 commit comments

Comments
 (0)