Skip to content

Conversation

@miaulalala
Copy link
Contributor

@miaulalala miaulalala commented Dec 2, 2025

RFC: extending the Entity class to support snowflake 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?
  • Resolves: #

TODO

  • ...

Checklist

@miaulalala miaulalala added this to the Nextcloud 33 milestone Dec 2, 2025
@miaulalala miaulalala self-assigned this Dec 2, 2025
@miaulalala miaulalala requested a review from a team as a code owner December 2, 2025 13:10
@miaulalala miaulalala requested review from ArtificialOwl and icewind1991 and removed request for a team December 2, 2025 13:10
Copy link
Member

@CarlSchwan CarlSchwan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Llike the Id :)

@come-nc
Copy link
Contributor

come-nc commented Dec 2, 2025

We should rename IGenerator and IDecoder to ISnowflakeGenerator and ISnowflakeDecoder, otherwise after a use all code is ambiguous.
A value object for decoded snowflakes would be good as well.

@miaulalala
Copy link
Contributor Author

We should rename IGenerator and IDecoder to ISnowflakeGenerator and ISnowflakeDecoder, otherwise after a use all code is ambiguous. A value object for decoded snowflakes would be good as well.

Added

Copy link
Collaborator

@Altahrim Altahrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we introduce a Snowflake DTO, I think Decoder should return it directly

@miaulalala
Copy link
Contributor Author

Would it make sense to cache the decoded snowflake ID? Seems like there's quite a few expensive calculations going on.

@Altahrim
Copy link
Collaborator

Altahrim commented Dec 4, 2025

We can still add a cache later if needed but decoding on 64 bits mainly involve binary operations, it should be fast.
32 bit is more complicated 😓

@miaulalala miaulalala requested a review from Altahrim December 4, 2025 13:51
@miaulalala miaulalala force-pushed the feat/noid/extend-entity-to-be-snoflake-aware branch 2 times, most recently from 83d0781 to 7d1ded5 Compare December 16, 2025 11:14
Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also be on the "public readonly properties" team, but that’s bikeshedding.

@miaulalala miaulalala force-pushed the feat/noid/extend-entity-to-be-snoflake-aware branch from 7d1ded5 to 75a21de Compare December 16, 2025 15:14
@miaulalala miaulalala added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Dec 16, 2025
Copy link
Collaborator

@Altahrim Altahrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With same comment than Côme :)

Copy link
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes would be nice. Also I would prefer if the changes were done in multiple commits. I also noticed the name of the DI variable is inconsistent, maybe you can fix that as well.

miaulalala added a commit to nextcloud/spreed that referenced this pull request Dec 18, 2025
- [ ] needs nextcloud/server#56795
- [ ] needs #16508

Skipping CI for now, amend the commit message and remove the skip-ci param when ready to rebase and merge

[skip-ci]

Signed-off-by: Anna Larch <anna@nextcloud.com>
@miaulalala miaulalala force-pushed the feat/noid/extend-entity-to-be-snoflake-aware branch from 75a21de to 8d35e95 Compare December 18, 2025 22:34
miaulalala added a commit to nextcloud/spreed that referenced this pull request Dec 18, 2025
- [ ] needs nextcloud/server#56795
- [ ] needs #16508

Skipping CI for now, amend the commit message and remove the skip-ci param when ready to rebase and merge

[skip ci]

Signed-off-by: Anna Larch <anna@nextcloud.com>
@miaulalala miaulalala force-pushed the feat/noid/extend-entity-to-be-snoflake-aware branch from ba2f797 to 67b168a Compare December 23, 2025 08:49
$this->id = Server::get(ISnowflakeGenerator::class)->nextId();
$this->markFieldUpdated('id');
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a getId method which returns a string. We can't relly on the one from Entity as it returns an int and this will break on 32 bits system

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants