-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(snowflake): extend Entity class to support snowflakes #56795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
miaulalala
wants to merge
12
commits into
master
Choose a base branch
from
feat/noid/extend-entity-to-be-snoflake-aware
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+285
−169
Open
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3ae4815
refactor!: Rename Snowflake Generator and Decoder
miaulalala 6ae368c
feat: extend Entity and adjust QBMapper to support Snowflake IDs
miaulalala dcbc671
fixup! refactor!: Rename Snowflake Generator and Decoder and introduc…
miaulalala 11459c2
fixup! refactor!: Rename Snowflake Generator and Decoder and introduc…
miaulalala 36fe8be
refactor: move existing usages of snoflake IDs SnowflakeAwareEntity
miaulalala 44ffccd
fixup! feat: extend Entity and adjust QBMapper to support Snowflake IDs
miaulalala 577b145
fixup! refactor: move existing usages of snoflake IDs SnowflakeAwareE…
miaulalala 9c46c77
fixup! feat: extend Entity and adjust QBMapper to support Snowflake IDs
miaulalala d3bc137
fixup! feat: extend Entity and adjust QBMapper to support Snowflake IDs
miaulalala 47936fa
fixup! feat: extend Entity and adjust QBMapper to support Snowflake IDs
miaulalala 67b168a
fixup! feat: extend Entity and adjust QBMapper to support Snowflake IDs
miaulalala 29d972b
feat: Adapt a bit the snowflake ids API
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixup! refactor!: Rename Snowflake Generator and Decoder and introduc…
…e the Snowflake DTO
- Loading branch information
commit dcbc6712a17ed3907216565e61821a25dba8b93b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-only | ||
| */ | ||
|
|
||
| namespace OCP\Snowflake; | ||
|
|
||
| use OCP\AppFramework\Attribute\Consumable; | ||
|
|
||
| /** | ||
| * Nextcloud Snowflake ID decoder | ||
| * | ||
| * @see \OCP\Snowflake\ISnowflakeGenerator for format | ||
| * @since 33.0.0 | ||
| */ | ||
| #[Consumable(since: '33.0.0')] | ||
| interface ISnowflakeDecoder { | ||
| /** | ||
| * Decode information contained into Snowflake ID | ||
| * | ||
| * It includes: | ||
| * - server ID: identify server on which ID was generated | ||
| * - sequence ID: sequence number (number of snowflakes generated in the same second) | ||
| * - createdAt: timestamp at which ID was generated | ||
| * - isCli: if ID was generated using CLI or not | ||
| * | ||
| * @return Snowflake | ||
| * @since 33.0 | ||
| */ | ||
| public function decode(string $snowflakeId): Snowflake; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-only | ||
| */ | ||
|
|
||
| namespace OCP\Snowflake; | ||
|
|
||
| use OCP\AppFramework\Attribute\Consumable; | ||
|
|
||
| /** | ||
| * Nextcloud Snowflake ID generator | ||
| * | ||
| * Customized version of Snowflake IDs for Nextcloud: | ||
| * 1 bit : Unused, always 0, avoid issue with PHP signed integers. | ||
| * 31 bits: Timestamp from 2025-10-01. Allows to store a bit more than 68 years. Allows to find creation time. | ||
| * 10 bits: Milliseconds (between 0 and 999) | ||
| * 9 bits: Server ID, identify server which generated the ID (between 0 and 1023) | ||
| * 1 bit : CLI or Web (0 or 1) | ||
| * 12 bits: Sequence ID, usually a serial number of objects created in the same number on same server (between 0 and 4095) | ||
| * | ||
| * @since 33.0.0 | ||
| */ | ||
| #[Consumable(since: '33.0.0')] | ||
| interface ISnowflakeGenerator { | ||
|
|
||
| /** | ||
| * Offset applied on timestamps to keep it short | ||
| * Start from 2025-10-01 at 00:00:00 | ||
| * | ||
| * @since 33.0 | ||
| */ | ||
| public const TS_OFFSET = 1759276800; | ||
|
|
||
| /** | ||
| * Get a new Snowflake ID. | ||
| * | ||
| * Each call to this method is guaranteed to return a different ID. | ||
| * | ||
| * @since 33.0 | ||
| */ | ||
| public function nextId(): string; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCP\Snowflake; | ||
|
|
||
| use OCP\AppFramework\Attribute\Consumable; | ||
|
|
||
| /** | ||
| * Nextcloud Snowflake DTO | ||
| * | ||
| * @since 33.0.0 | ||
| */ | ||
| #[Consumable(since: '33.0.0')] | ||
| final readonly class Snowflake { | ||
| /** | ||
| * @psalm-param int<0,1023> $serverId | ||
| * @psalm-param int<0,4095> $sequenceId | ||
| * @psalm-param non-negative-int $seconds | ||
| * @psalm-param int<0,999> $milliseconds | ||
| */ | ||
| public function __construct( | ||
| private int $serverId, | ||
| private int $sequenceId, | ||
| private bool $isCli, | ||
| private int $seconds, | ||
| private int $milliseconds, | ||
| private \DateTimeImmutable $createdAt, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * @psalm-return int<0,1023> | ||
| */ | ||
| public function getServerId(): int { | ||
miaulalala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return $this->serverId; | ||
| } | ||
|
|
||
| /** | ||
| * @psalm-return int<0,4095> | ||
| */ | ||
| public function getSequenceId(): int { | ||
| return $this->sequenceId; | ||
| } | ||
|
|
||
| public function isCli(): bool { | ||
| return $this->isCli; | ||
| } | ||
|
|
||
| /** | ||
| * @psalm-return non-negative-int | ||
| */ | ||
| public function getSeconds(): int { | ||
| return $this->seconds; | ||
| } | ||
|
|
||
| /** | ||
| * @psalm-return int<0,999> | ||
| */ | ||
| public function getMilliseconds(): int { | ||
| return $this->milliseconds; | ||
| } | ||
|
|
||
| public function getCreatedAt(): \DateTimeImmutable { | ||
| return $this->createdAt; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.