Skip to content

Commit 75a21de

Browse files
committed
feat(snowflake): extend Entity class to support snowflakes
RFC: extending the Entity class to support snoflake IDs automagically Good ides - yes / no? Benefits: - every entity that supports snowflake IDs can automagically handle them by implementing the `SnowflakeAwareEntity` instead of the regular `Entity` - No adding IGenerator / IDecoder in every entity class - centralised method support for `createdAt`, `setId`, and anything else we would like to offer separately - get entire decoded snowflake id from the entity Drawbacks: - Will it work the way I think it should? Signed-off-by: Anna Larch <[email protected]>
1 parent 1829269 commit 75a21de

28 files changed

+264
-118
lines changed

apps/files_sharing/lib/AppInfo/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ public function registerEventsScripts(IEventDispatcher $dispatcher): void {
142142
// notifications api to accept incoming user shares
143143
$dispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event): void {
144144
/** @var Listener $listener */
145-
$listener = $this->getContainer()->query(Listener::class);
145+
$listener = $this->getContainer()->get(Listener::class);
146146
$listener->shareNotification($event);
147147
});
148148
$dispatcher->addListener(IGroup::class . '::postAddUser', function ($event): void {
149149
if (!$event instanceof OldGenericEvent) {
150150
return;
151151
}
152152
/** @var Listener $listener */
153-
$listener = $this->getContainer()->query(Listener::class);
153+
$listener = $this->getContainer()->get(Listener::class);
154154
$listener->userAddedToGroup($event);
155155
});
156156
}

build/psalm-baseline.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,12 +1604,6 @@
16041604
<code><![CDATA[public function __construct(]]></code>
16051605
</ConstructorSignatureMismatch>
16061606
</file>
1607-
<file src="apps/files_sharing/lib/AppInfo/Application.php">
1608-
<DeprecatedMethod>
1609-
<code><![CDATA[query]]></code>
1610-
<code><![CDATA[query]]></code>
1611-
</DeprecatedMethod>
1612-
</file>
16131607
<file src="apps/files_sharing/lib/Capabilities.php">
16141608
<DeprecatedMethod>
16151609
<code><![CDATA[getAppValue]]></code>

core/BackgroundJobs/MovePreviewJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use OCP\IAppConfig;
2727
use OCP\IConfig;
2828
use OCP\IDBConnection;
29-
use OCP\Snowflake\IGenerator;
29+
use OCP\Snowflake\ISnowflakeGenerator;
3030
use Override;
3131
use Psr\Log\LoggerInterface;
3232

@@ -45,7 +45,7 @@ public function __construct(
4545
private readonly IMimeTypeDetector $mimeTypeDetector,
4646
private readonly IMimeTypeLoader $mimeTypeLoader,
4747
private readonly LoggerInterface $logger,
48-
private readonly IGenerator $generator,
48+
private readonly ISnowflakeGenerator $generator,
4949
IAppDataFactory $appDataFactory,
5050
) {
5151
parent::__construct($time);

core/Command/SnowflakeDecodeId.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
*/
99
namespace OC\Core\Command;
1010

11-
use OCP\Snowflake\IDecoder;
11+
use OCP\Snowflake\ISnowflakeDecoder;
1212
use Symfony\Component\Console\Helper\Table;
1313
use Symfony\Component\Console\Input\InputArgument;
1414
use Symfony\Component\Console\Input\InputInterface;
1515
use Symfony\Component\Console\Output\OutputInterface;
1616

1717
class SnowflakeDecodeId extends Base {
1818
public function __construct(
19-
private readonly IDecoder $decoder,
19+
private readonly ISnowflakeDecoder $decoder,
2020
) {
2121
parent::__construct();
2222
}
@@ -36,13 +36,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3636

3737
$rows = [
3838
['Snowflake ID', $snowflakeId],
39-
['Seconds', $data['seconds']],
40-
['Milliseconds', $data['milliseconds']],
41-
['Created from CLI', $data['isCli'] ? 'yes' : 'no'],
42-
['Server ID', $data['serverId']],
43-
['Sequence ID', $data['sequenceId']],
44-
['Creation timestamp', $data['createdAt']->format('U.v')],
45-
['Creation date', $data['createdAt']->format('Y-m-d H:i:s.v')],
39+
['Seconds', $data->getSeconds()],
40+
['Milliseconds', $data->getMilliseconds()],
41+
['Created from CLI', $data->isCli() ? 'yes' : 'no'],
42+
['Server ID', $data->getServerId()],
43+
['Sequence ID', $data->getSequenceId()],
44+
['Creation timestamp', $data->getCreatedAt()->format('U.v')],
45+
['Creation date', $data->getCreatedAt()->format('Y-m-d H:i:s.v')],
4646
];
4747

4848
$table = new Table($output);

lib/composer/composer/autoload_classmap.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
'OCP\\AppFramework\\Db\\IMapperException' => $baseDir . '/lib/public/AppFramework/Db/IMapperException.php',
7979
'OCP\\AppFramework\\Db\\MultipleObjectsReturnedException' => $baseDir . '/lib/public/AppFramework/Db/MultipleObjectsReturnedException.php',
8080
'OCP\\AppFramework\\Db\\QBMapper' => $baseDir . '/lib/public/AppFramework/Db/QBMapper.php',
81+
'OCP\\AppFramework\\Db\\SnowflakeAwareEntity' => $baseDir . '/lib/public/AppFramework/Db/SnowflakeAwareEntity.php',
8182
'OCP\\AppFramework\\Db\\TTransactional' => $baseDir . '/lib/public/AppFramework/Db/TTransactional.php',
8283
'OCP\\AppFramework\\Http' => $baseDir . '/lib/public/AppFramework/Http.php',
8384
'OCP\\AppFramework\\Http\\Attribute\\ARateLimit' => $baseDir . '/lib/public/AppFramework/Http/Attribute/ARateLimit.php',
@@ -830,8 +831,9 @@
830831
'OCP\\Share_Backend' => $baseDir . '/lib/public/Share_Backend.php',
831832
'OCP\\Share_Backend_Collection' => $baseDir . '/lib/public/Share_Backend_Collection.php',
832833
'OCP\\Share_Backend_File_Dependent' => $baseDir . '/lib/public/Share_Backend_File_Dependent.php',
833-
'OCP\\Snowflake\\IDecoder' => $baseDir . '/lib/public/Snowflake/IDecoder.php',
834-
'OCP\\Snowflake\\IGenerator' => $baseDir . '/lib/public/Snowflake/IGenerator.php',
834+
'OCP\\Snowflake\\ISnowflakeDecoder' => $baseDir . '/lib/public/Snowflake/ISnowflakeDecoder.php',
835+
'OCP\\Snowflake\\ISnowflakeGenerator' => $baseDir . '/lib/public/Snowflake/ISnowflakeGenerator.php',
836+
'OCP\\Snowflake\\Snowflake' => $baseDir . '/lib/public/Snowflake/Snowflake.php',
835837
'OCP\\SpeechToText\\Events\\AbstractTranscriptionEvent' => $baseDir . '/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php',
836838
'OCP\\SpeechToText\\Events\\TranscriptionFailedEvent' => $baseDir . '/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php',
837839
'OCP\\SpeechToText\\Events\\TranscriptionSuccessfulEvent' => $baseDir . '/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php',
@@ -2125,10 +2127,10 @@
21252127
'OC\\Share\\Helper' => $baseDir . '/lib/private/Share/Helper.php',
21262128
'OC\\Share\\Share' => $baseDir . '/lib/private/Share/Share.php',
21272129
'OC\\Snowflake\\APCuSequence' => $baseDir . '/lib/private/Snowflake/APCuSequence.php',
2128-
'OC\\Snowflake\\Decoder' => $baseDir . '/lib/private/Snowflake/Decoder.php',
21292130
'OC\\Snowflake\\FileSequence' => $baseDir . '/lib/private/Snowflake/FileSequence.php',
2130-
'OC\\Snowflake\\Generator' => $baseDir . '/lib/private/Snowflake/Generator.php',
21312131
'OC\\Snowflake\\ISequence' => $baseDir . '/lib/private/Snowflake/ISequence.php',
2132+
'OC\\Snowflake\\SnowflakeDecoder' => $baseDir . '/lib/private/Snowflake/SnowflakeDecoder.php',
2133+
'OC\\Snowflake\\SnowflakeGenerator' => $baseDir . '/lib/private/Snowflake/SnowflakeGenerator.php',
21322134
'OC\\SpeechToText\\SpeechToTextManager' => $baseDir . '/lib/private/SpeechToText/SpeechToTextManager.php',
21332135
'OC\\SpeechToText\\TranscriptionJob' => $baseDir . '/lib/private/SpeechToText/TranscriptionJob.php',
21342136
'OC\\StreamImage' => $baseDir . '/lib/private/StreamImage.php',

lib/composer/composer/autoload_static.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
119119
'OCP\\AppFramework\\Db\\IMapperException' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Db/IMapperException.php',
120120
'OCP\\AppFramework\\Db\\MultipleObjectsReturnedException' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Db/MultipleObjectsReturnedException.php',
121121
'OCP\\AppFramework\\Db\\QBMapper' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Db/QBMapper.php',
122+
'OCP\\AppFramework\\Db\\SnowflakeAwareEntity' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Db/SnowflakeAwareEntity.php',
122123
'OCP\\AppFramework\\Db\\TTransactional' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Db/TTransactional.php',
123124
'OCP\\AppFramework\\Http' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http.php',
124125
'OCP\\AppFramework\\Http\\Attribute\\ARateLimit' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/Attribute/ARateLimit.php',
@@ -871,8 +872,9 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
871872
'OCP\\Share_Backend' => __DIR__ . '/../../..' . '/lib/public/Share_Backend.php',
872873
'OCP\\Share_Backend_Collection' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_Collection.php',
873874
'OCP\\Share_Backend_File_Dependent' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_File_Dependent.php',
874-
'OCP\\Snowflake\\IDecoder' => __DIR__ . '/../../..' . '/lib/public/Snowflake/IDecoder.php',
875-
'OCP\\Snowflake\\IGenerator' => __DIR__ . '/../../..' . '/lib/public/Snowflake/IGenerator.php',
875+
'OCP\\Snowflake\\ISnowflakeDecoder' => __DIR__ . '/../../..' . '/lib/public/Snowflake/ISnowflakeDecoder.php',
876+
'OCP\\Snowflake\\ISnowflakeGenerator' => __DIR__ . '/../../..' . '/lib/public/Snowflake/ISnowflakeGenerator.php',
877+
'OCP\\Snowflake\\Snowflake' => __DIR__ . '/../../..' . '/lib/public/Snowflake/Snowflake.php',
876878
'OCP\\SpeechToText\\Events\\AbstractTranscriptionEvent' => __DIR__ . '/../../..' . '/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php',
877879
'OCP\\SpeechToText\\Events\\TranscriptionFailedEvent' => __DIR__ . '/../../..' . '/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php',
878880
'OCP\\SpeechToText\\Events\\TranscriptionSuccessfulEvent' => __DIR__ . '/../../..' . '/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php',
@@ -2166,10 +2168,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
21662168
'OC\\Share\\Helper' => __DIR__ . '/../../..' . '/lib/private/Share/Helper.php',
21672169
'OC\\Share\\Share' => __DIR__ . '/../../..' . '/lib/private/Share/Share.php',
21682170
'OC\\Snowflake\\APCuSequence' => __DIR__ . '/../../..' . '/lib/private/Snowflake/APCuSequence.php',
2169-
'OC\\Snowflake\\Decoder' => __DIR__ . '/../../..' . '/lib/private/Snowflake/Decoder.php',
21702171
'OC\\Snowflake\\FileSequence' => __DIR__ . '/../../..' . '/lib/private/Snowflake/FileSequence.php',
2171-
'OC\\Snowflake\\Generator' => __DIR__ . '/../../..' . '/lib/private/Snowflake/Generator.php',
21722172
'OC\\Snowflake\\ISequence' => __DIR__ . '/../../..' . '/lib/private/Snowflake/ISequence.php',
2173+
'OC\\Snowflake\\SnowflakeDecoder' => __DIR__ . '/../../..' . '/lib/private/Snowflake/SnowflakeDecoder.php',
2174+
'OC\\Snowflake\\SnowflakeGenerator' => __DIR__ . '/../../..' . '/lib/private/Snowflake/SnowflakeGenerator.php',
21732175
'OC\\SpeechToText\\SpeechToTextManager' => __DIR__ . '/../../..' . '/lib/private/SpeechToText/SpeechToTextManager.php',
21742176
'OC\\SpeechToText\\TranscriptionJob' => __DIR__ . '/../../..' . '/lib/private/SpeechToText/TranscriptionJob.php',
21752177
'OC\\StreamImage' => __DIR__ . '/../../..' . '/lib/private/StreamImage.php',

lib/private/BackgroundJob/JobList.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use OCP\DB\QueryBuilder\IQueryBuilder;
1717
use OCP\IConfig;
1818
use OCP\IDBConnection;
19-
use OCP\Snowflake\IGenerator;
19+
use OCP\Snowflake\ISnowflakeGenerator;
2020
use Override;
2121
use Psr\Container\ContainerExceptionInterface;
2222
use Psr\Log\LoggerInterface;
@@ -34,7 +34,7 @@ public function __construct(
3434
protected readonly IConfig $config,
3535
protected readonly ITimeFactory $timeFactory,
3636
protected readonly LoggerInterface $logger,
37-
protected readonly IGenerator $generator,
37+
protected readonly ISnowflakeGenerator $snowflakeGenerator,
3838
) {
3939
}
4040

@@ -55,7 +55,7 @@ public function add(IJob|string $job, mixed $argument = null, ?int $firstCheck =
5555
if (!$this->has($job, $argument)) {
5656
$query->insert('jobs')
5757
->values([
58-
'id' => $query->createNamedParameter($this->generator->nextId()),
58+
'id' => $query->createNamedParameter($this->snowflakeGenerator->nextId()),
5959
'class' => $query->createNamedParameter($class),
6060
'argument' => $query->createNamedParameter($argumentJson),
6161
'argument_hash' => $query->createNamedParameter(hash('sha256', $argumentJson)),

lib/private/Preview/Db/PreviewMapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use OCP\DB\QueryBuilder\IQueryBuilder;
1616
use OCP\Files\IMimeTypeLoader;
1717
use OCP\IDBConnection;
18-
use OCP\Snowflake\IGenerator;
18+
use OCP\Snowflake\ISnowflakeGenerator;
1919
use Override;
2020

2121
/**
@@ -30,7 +30,7 @@ class PreviewMapper extends QBMapper {
3030
public function __construct(
3131
IDBConnection $db,
3232
private readonly IMimeTypeLoader $mimeTypeLoader,
33-
private readonly IGenerator $snowflake,
33+
private readonly ISnowflakeGenerator $snowflake,
3434
) {
3535
parent::__construct($db, self::TABLE_NAME, Preview::class);
3636
}

lib/private/Preview/Generator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use OCP\IStreamImage;
2424
use OCP\Preview\BeforePreviewFetchedEvent;
2525
use OCP\Preview\IVersionedPreviewFile;
26-
use OCP\Snowflake\IGenerator;
26+
use OCP\Snowflake\ISnowflakeGenerator;
2727
use Psr\Log\LoggerInterface;
2828

2929
class Generator {
@@ -38,7 +38,7 @@ public function __construct(
3838
private LoggerInterface $logger,
3939
private PreviewMapper $previewMapper,
4040
private StorageFactory $storageFactory,
41-
private IGenerator $snowflakeGenerator,
41+
private ISnowflakeGenerator $snowflakeGenerator,
4242
) {
4343
}
4444

lib/private/Preview/Storage/LocalPreviewStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use OCP\IAppConfig;
2323
use OCP\IConfig;
2424
use OCP\IDBConnection;
25-
use OCP\Snowflake\IGenerator;
25+
use OCP\Snowflake\ISnowflakeGenerator;
2626
use Override;
2727
use Psr\Log\LoggerInterface;
2828
use RecursiveDirectoryIterator;
@@ -39,7 +39,7 @@ public function __construct(
3939
private readonly IDBConnection $connection,
4040
private readonly IMimeTypeDetector $mimeTypeDetector,
4141
private readonly LoggerInterface $logger,
42-
private readonly IGenerator $generator,
42+
private readonly ISnowflakeGenerator $generator,
4343
) {
4444
$this->instanceId = $this->config->getSystemValueString('instanceid');
4545
$this->rootFolder = $this->config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data');

0 commit comments

Comments
 (0)