Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e40dd2a
fix(FileListener): Process file events asynchronously
marcelklehr Dec 15, 2025
c0d40dd
fix: run cs:fix and fix psalm issues
marcelklehr Dec 15, 2025
8ca821e
fix: Fix psalm issues
marcelklehr Dec 15, 2025
d6e4f25
fix: Choose shorter pk index name
marcelklehr Dec 15, 2025
0e5f2e5
refactor: Process all fs events asynchronously
marcelklehr Dec 16, 2025
a8fb342
fix: Fix psalm issues and run cs:fix
marcelklehr Dec 16, 2025
19f4aeb
fix: Fix file listener tests
marcelklehr Dec 16, 2025
200a469
fix: Fix FsActionmapper
marcelklehr Dec 17, 2025
6e442b2
fix: Fix phpunit
marcelklehr Dec 17, 2025
69429c3
Fix: Remove old event listeners
marcelklehr Dec 17, 2025
82f7850
Fix: Update test bootstrap code
marcelklehr Dec 17, 2025
3b2f850
Fix: Fix tests by re-registering fs hooks
marcelklehr Dec 18, 2025
4411763
tests: Try to fix tests by enabling files_external app
marcelklehr Dec 18, 2025
82d555b
tests: add debug logs
marcelklehr Dec 18, 2025
693994f
tests: Clear trashbin before running tests
marcelklehr Dec 18, 2025
8de39a0
fix(FileListener): Do not consider events in trashbin
marcelklehr Dec 18, 2025
88fc3ce
fix: Appease linters
marcelklehr Dec 18, 2025
bac8ee2
fix: Update psalm baseline
marcelklehr Dec 18, 2025
8684d31
tests: Add --verbose flag to cron run and make sure deletion is actua…
marcelklehr Dec 18, 2025
e1b1377
fix(FsActionService): Pass userId to bg job to allow finding nodes vi…
marcelklehr Dec 18, 2025
481b0d1
fix: Update psalm baseline
marcelklehr Dec 18, 2025
d710e38
tests(cluster-faces): Add `occ upgrade` command in case it's needed
marcelklehr Dec 18, 2025
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
1 change: 1 addition & 0 deletions .github/workflows/cluster-faces-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ jobs:
- name: Run clustering
if: steps.clustering-cache.outputs.cache-hit != 'true'
run: |
./occ upgrade # in case server master has new migrations in the meantime
./occ recognize:cluster-faces -b 10000
./occ recognize:cluster-faces -b 10000
./occ recognize:cluster-faces -b 10000
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/files-scan-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ jobs:
GITHUB_REF: ${{ github.ref }}
run: |
./occ files:scan admin -vvv
for run in {1..100}; do php cron.php -v; done
rm data/admin/files/res/alpine.JPG
./occ files:scan admin -vvv
for run in {1..100}; do php cron.php; done
for run in {1..100}; do php cron.php -v; done
[ ! -z "$(./occ tag:list)" ]

- name: Print tags
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/phpunit-mariadb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ jobs:
mkdir data
./occ maintenance:install --verbose --database=mysql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
./occ app:enable --force ${{ env.APP_NAME }}
./occ app:enable files_external

- name: Check PHPUnit script is defined
id: check_phpunit
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/phpunit-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ jobs:
mkdir data
./occ maintenance:install --verbose --database=mysql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
./occ app:enable --force ${{ env.APP_NAME }}
./occ app:enable files_external

- name: Check PHPUnit script is defined
id: check_phpunit
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/phpunit-pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ jobs:
mkdir data
./occ maintenance:install --verbose --database=pgsql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
./occ app:enable --force ${{ env.APP_NAME }}
./occ app:enable files_external

- name: Check PHPUnit script is defined
id: check_phpunit
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/phpunit-sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ jobs:
mkdir data
./occ maintenance:install --verbose --database=sqlite --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
./occ app:enable --force ${{ env.APP_NAME }}
./occ app:enable files_external

- name: Check PHPUnit script is defined
id: check_phpunit
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"psalm": "psalm.phar",
"psalm:update-baseline": "psalm.phar --threads=1 --update-baseline",
"psalm:update-baseline:force": "psalm.phar --threads=1 --update-baseline --set-baseline=psalm-baseline.xml",
"psalm": "psalm",
"psalm:update-baseline": "psalm --threads=1 --update-baseline",
"psalm:update-baseline:force": "psalm --threads=1 --update-baseline --set-baseline=psalm-baseline.xml",
"test:unit": "phpunit --config tests/phpunit.xml",
"post-install-cmd": [
"@composer bin all install --ansi",
Expand Down
16 changes: 4 additions & 12 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
use OCP\Files\Events\Node\NodeRenamedEvent;
use OCP\Files\Events\NodeRemovedFromCache;
use OCP\SabrePluginEvent;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\Events\ShareDeletedEvent;

final class Application extends App implements IBootstrap {
public const APP_ID = 'recognize';
Expand All @@ -42,16 +40,10 @@ public function __construct() {
$dispatcher->addServiceListener(BeforeNodeRenamedEvent::class, FileListener::class);
$dispatcher->addServiceListener(CacheEntryInsertedEvent::class, FileListener::class);
$dispatcher->addServiceListener(NodeRemovedFromCache::class, FileListener::class);
// These events were added mid-way through NC 30, 31
if (class_exists('OCP\Files\Config\Event\UserMountAddedEvent')) {
$dispatcher->addServiceListener('OCP\Files\Config\Event\UserMountAddedEvent', FileListener::class);
$dispatcher->addServiceListener('OCP\Files\Config\Event\UserMountRemovedEvent', FileListener::class);
// it is not fired as of now, Added and Removed events are fired instead in that order
// $context->addServiceListener('OCP\Files\Config\Event\UserMountUpdatedEvent', FileListener::class);
} else {
$dispatcher->addServiceListener(ShareCreatedEvent::class, FileListener::class);
$dispatcher->addServiceListener(ShareDeletedEvent::class, FileListener::class);
}
$dispatcher->addServiceListener('OCP\Files\Config\Event\UserMountAddedEvent', FileListener::class);
$dispatcher->addServiceListener('OCP\Files\Config\Event\UserMountRemovedEvent', FileListener::class);
// it is not fired as of now, Added and Removed events are fired instead in that order
// $context->addServiceListener('OCP\Files\Config\Event\UserMountUpdatedEvent', FileListener::class);
}

public function register(IRegistrationContext $context): void {
Expand Down
68 changes: 68 additions & 0 deletions lib/BackgroundJobs/ProcessFsActionsJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/*
* Copyright (c) 2021-2022 The Recognize contributors.
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
*/
declare(strict_types=1);
namespace OCA\Recognize\BackgroundJobs;

use OCA\Recognize\Db\FsAccessUpdate;
use OCA\Recognize\Db\FsActionMapper;
use OCA\Recognize\Db\FsCreation;
use OCA\Recognize\Db\FsDeletion;
use OCA\Recognize\Db\FsMove;
use OCA\Recognize\Service\FsActionService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\TimedJob;
use OCP\DB\Exception;
use Psr\Log\LoggerInterface;

final class ProcessFsActionsJob extends TimedJob {

public function __construct(
ITimeFactory $timeFactory,
private FsActionService $accessUpdateService,
private IJobList $jobList,
private FsActionMapper $accessUpdateMapper,
private LoggerInterface $logger,
) {
parent::__construct($timeFactory);
$this->setInterval(5 * 60);
$this->setTimeSensitivity(self::TIME_SENSITIVE);
}

/**
* @param array{storage_id:int, type: class-string<FsAccessUpdate|FsCreation|FsDeletion|FsMove>} $argument
* @return void
*/
protected function run($argument): void {
$storageId = $argument['storage_id'] ?? null;
$className = $argument['type'];

if (isset($storageId)) {
$this->accessUpdateService->processActionsByClassAndStorageId($className, $storageId);
try {
$remainingCount = $this->accessUpdateMapper->countByStorageId($className, $storageId);
} catch (Exception $e) {
$this->logger->error('Failed to count fs actions: ' . $e->getMessage(), ['exception' => $e]);
$remainingCount = 1;
}
} else {
$this->accessUpdateService->processActionsByClass($className);
try {
$remainingCount = $this->accessUpdateMapper->count($className);
} catch (Exception $e) {
$this->logger->error('Failed to count fs actions: ' . $e->getMessage(), ['exception' => $e]);
$remainingCount = 1;
}
}


if ($remainingCount === 0) {
// Remove job from queue
$this->jobList->remove(self::class, $argument);
}
}
}
2 changes: 1 addition & 1 deletion lib/Clustering/DualTreeClique.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function propagateSetChanges(array &$labelToSetId) {

$labels = $this->dataset->labels();
$lastLabel = array_pop($labels);
if (!isset($labelToSetId[$lastLabel])) {
if (!isset($lastLabel) || !isset($labelToSetId[$lastLabel])) {
return null;
}
$setId = $labelToSetId[$lastLabel];
Expand Down
43 changes: 43 additions & 0 deletions lib/Db/FsAccessUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* Copyright (c) 2022 The Recognize contributors.
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
*/
declare(strict_types=1);
namespace OCA\Recognize\Db;

use OCP\AppFramework\Db\Entity;

/**
* Class FsAccessUpdate
*
* @package OCA\Recognize\Db
* @method int getStorageId()
* @method setStorageId(int $storageId)
* @method int getRootId()
* @method setRootId(int $rootId)
*/
final class FsAccessUpdate extends Entity {
protected ?int $storageId = null;
protected ?int $rootId = null;

/**
* @var string[]
*/
public static array $columns = ['id', 'storage_id', 'root_id'];

/**
* @var string[]
*/
public static array $fields = ['id', 'storageId', 'rootId'];

public static string $tableName = 'recognize_fs_access_updates';

public function __construct() {
// add types in constructor
$this->addType('id', 'integer');
$this->addType('storageId', 'integer');
$this->addType('rootId', 'integer');
}
}
Loading
Loading