mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-16 12:58:00 +00:00
b522588d98
# Which Problems Are Solved Float64 which was used for the event.Position field is [not precise in go and gets rounded](https://github.com/golang/go/issues/47300). This can lead to unprecies position tracking of events and therefore projections especially on cockcoachdb as the position used there is a big number. example of a unprecies position: exact: 1725257931223002628 float64: 1725257931223002624.000000 # How the Problems Are Solved The float64 was replaced by [github.com/jackc/pgx-shopspring-decimal](https://github.com/jackc/pgx-shopspring-decimal). # Additional Changes Correct behaviour of makefile for load tests. Rename `latestSequence`-queries to `latestPosition`
109 lines
2.3 KiB
Go
109 lines
2.3 KiB
Go
package eventstore
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/shopspring/decimal"
|
|
"github.com/zitadel/logging"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
var (
|
|
_ eventstore.Event = (*event)(nil)
|
|
)
|
|
|
|
type event struct {
|
|
aggregate *eventstore.Aggregate
|
|
creator string
|
|
revision uint16
|
|
typ eventstore.EventType
|
|
createdAt time.Time
|
|
sequence uint64
|
|
position decimal.Decimal
|
|
payload Payload
|
|
}
|
|
|
|
func commandToEvent(sequence *latestSequence, command eventstore.Command) (_ *event, err error) {
|
|
var payload Payload
|
|
if command.Payload() != nil {
|
|
payload, err = json.Marshal(command.Payload())
|
|
if err != nil {
|
|
logging.WithError(err).Warn("marshal payload failed")
|
|
return nil, zerrors.ThrowInternal(err, "V3-MInPK", "Errors.Internal")
|
|
}
|
|
}
|
|
return &event{
|
|
aggregate: sequence.aggregate,
|
|
creator: command.Creator(),
|
|
revision: command.Revision(),
|
|
typ: command.Type(),
|
|
payload: payload,
|
|
sequence: sequence.sequence,
|
|
}, nil
|
|
}
|
|
|
|
// CreationDate implements [eventstore.Event]
|
|
func (e *event) CreationDate() time.Time {
|
|
return e.CreatedAt()
|
|
}
|
|
|
|
// EditorUser implements [eventstore.Event]
|
|
func (e *event) EditorUser() string {
|
|
return e.Creator()
|
|
}
|
|
|
|
// Aggregate implements [eventstore.Event]
|
|
func (e *event) Aggregate() *eventstore.Aggregate {
|
|
return e.aggregate
|
|
}
|
|
|
|
// Creator implements [eventstore.Event]
|
|
func (e *event) Creator() string {
|
|
return e.creator
|
|
}
|
|
|
|
// Revision implements [eventstore.Event]
|
|
func (e *event) Revision() uint16 {
|
|
return e.revision
|
|
}
|
|
|
|
// Type implements [eventstore.Event]
|
|
func (e *event) Type() eventstore.EventType {
|
|
return e.typ
|
|
}
|
|
|
|
// CreatedAt implements [eventstore.Event]
|
|
func (e *event) CreatedAt() time.Time {
|
|
return e.createdAt
|
|
}
|
|
|
|
// Sequence implements [eventstore.Event]
|
|
func (e *event) Sequence() uint64 {
|
|
return e.sequence
|
|
}
|
|
|
|
// Position implements [eventstore.Event]
|
|
func (e *event) Position() decimal.Decimal {
|
|
return e.position
|
|
}
|
|
|
|
// Unmarshal implements [eventstore.Event]
|
|
func (e *event) Unmarshal(ptr any) error {
|
|
if len(e.payload) == 0 {
|
|
return nil
|
|
}
|
|
if err := json.Unmarshal(e.payload, ptr); err != nil {
|
|
return zerrors.ThrowInternal(err, "V3-u8qVo", "Errors.Internal")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// DataAsBytes implements [eventstore.Event]
|
|
func (e *event) DataAsBytes() []byte {
|
|
return e.payload
|
|
}
|