zitadel/internal/repository/asset/asset.go
Silvan b5564572bc
feat(eventstore): increase parallel write capabilities (#5940)
This implementation increases parallel write capabilities of the eventstore.
Please have a look at the technical advisories: [05](https://zitadel.com/docs/support/advisory/a10005) and  [06](https://zitadel.com/docs/support/advisory/a10006).
The implementation of eventstore.push is rewritten and stored events are migrated to a new table `eventstore.events2`.
If you are using cockroach: make sure that the database user of ZITADEL has `VIEWACTIVITY` grant. This is used to query events.
2023-10-19 12:19:10 +02:00

88 lines
1.6 KiB
Go

package asset
import (
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
)
const (
AddedEventType = "asset.added"
RemovedEventType = "asset.removed"
)
type AddedEvent struct {
eventstore.BaseEvent `json:"-"`
StoreKey string `json:"storeKey"`
}
func (e *AddedEvent) Payload() interface{} {
return e
}
func (e *AddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
func NewAddedEvent(
base *eventstore.BaseEvent,
key string,
) *AddedEvent {
return &AddedEvent{
BaseEvent: *base,
StoreKey: key,
}
}
func AddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
e := &AddedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := event.Unmarshal(e)
if err != nil {
return nil, errors.ThrowInternal(err, "ASSET-1WEAx", "unable to unmarshal asset")
}
return e, nil
}
type RemovedEvent struct {
eventstore.BaseEvent `json:"-"`
StoreKey string `json:"storeKey"`
}
func (e *RemovedEvent) Payload() interface{} {
return e
}
func (e *RemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
func NewRemovedEvent(
base *eventstore.BaseEvent,
key string,
) *RemovedEvent {
return &RemovedEvent{
BaseEvent: *base,
StoreKey: key,
}
}
func RemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
e := &RemovedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := event.Unmarshal(e)
if err != nil {
return nil, errors.ThrowInternal(err, "ASSET-1m9PP", "unable to unmarshal asset")
}
return e, nil
}