feat(snowflake): extend Entity class to support snowflakes
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
SnowflakeAwareEntityinstead of the regularEntity - 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
- Code is properly formatted
- Sign-off message is added to all commits
- [ ] Tests (unit, integration, api and/or acceptance) are included
- [ ] Screenshots before/after for front-end changes
- [ ] Documentation (manuals or wiki) has been updated or is not required
- [ ] Backports requested where applicable (ex: critical bugfixes)
- [ ] Labels added where applicable (ex: bug/enhancement,
3. to review, feature component) - [ ] Milestone added for target branch/version (ex: 32.x for
stable32)
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.
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
Would it make sense to cache the decoded snowflake ID? Seems like there's quite a few expensive calculations going on.
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 :sweat:
@Altahrim should the mapper also handle IDs on insert?
Currently it's doing the following:
https://github.com/nextcloud/server/blob/bba96678826ba9b6726484ff05a1d7fd48cfa8b7/lib/public/AppFramework/Db/QBMapper.php#L117-L120
I'm thinking it might be possible to add a if ($entity instanceof SnowflakeAwareEntity) { $entity->setId()} ?