aboutsummaryrefslogtreecommitdiff
path: root/syncapi/storage/shared/syncserver.go
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-11-16 15:44:53 +0000
committerGitHub <noreply@github.com>2020-11-16 15:44:53 +0000
commit20a01bceb2869c810932eac217d96dc221953685 (patch)
tree639cd8656282ae231a46531f063d7d010320a582 /syncapi/storage/shared/syncserver.go
parentd8b526b603683879c012972707cdce44fff3c802 (diff)
Pass pointers to events — reloaded (#1583)
* Pass events as pointers * Fix lint errors * Update gomatrixserverlib * Update gomatrixserverlib * Update to matrix-org/gomatrixserverlib#240
Diffstat (limited to 'syncapi/storage/shared/syncserver.go')
-rw-r--r--syncapi/storage/shared/syncserver.go28
1 files changed, 14 insertions, 14 deletions
diff --git a/syncapi/storage/shared/syncserver.go b/syncapi/storage/shared/syncserver.go
index 2b82ee33..fd8ca041 100644
--- a/syncapi/storage/shared/syncserver.go
+++ b/syncapi/storage/shared/syncserver.go
@@ -57,7 +57,7 @@ type Database struct {
// If an event is not found in the database then it will be omitted from the list.
// Returns an error if there was a problem talking with the database.
// Does not include any transaction IDs in the returned events.
-func (d *Database) Events(ctx context.Context, eventIDs []string) ([]gomatrixserverlib.HeaderedEvent, error) {
+func (d *Database) Events(ctx context.Context, eventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error) {
streamEvents, err := d.OutputEvents.SelectEvents(ctx, nil, eventIDs)
if err != nil {
return nil, err
@@ -135,7 +135,7 @@ func (d *Database) GetStateEvent(
func (d *Database) GetStateEventsForRoom(
ctx context.Context, roomID string, stateFilter *gomatrixserverlib.StateFilter,
-) (stateEvents []gomatrixserverlib.HeaderedEvent, err error) {
+) (stateEvents []*gomatrixserverlib.HeaderedEvent, err error) {
stateEvents, err = d.CurrentRoomState.SelectCurrentState(ctx, nil, roomID, stateFilter)
return
}
@@ -144,7 +144,7 @@ func (d *Database) GetStateEventsForRoom(
// If the invite was successfully stored this returns the stream ID it was stored at.
// Returns an error if there was a problem communicating with the database.
func (d *Database) AddInviteEvent(
- ctx context.Context, inviteEvent gomatrixserverlib.HeaderedEvent,
+ ctx context.Context, inviteEvent *gomatrixserverlib.HeaderedEvent,
) (sp types.StreamPosition, err error) {
_ = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
sp, err = d.Invites.InsertInviteEvent(ctx, txn, inviteEvent)
@@ -223,8 +223,8 @@ func (d *Database) UpsertAccountData(
return
}
-func (d *Database) StreamEventsToEvents(device *userapi.Device, in []types.StreamEvent) []gomatrixserverlib.HeaderedEvent {
- out := make([]gomatrixserverlib.HeaderedEvent, len(in))
+func (d *Database) StreamEventsToEvents(device *userapi.Device, in []types.StreamEvent) []*gomatrixserverlib.HeaderedEvent {
+ out := make([]*gomatrixserverlib.HeaderedEvent, len(in))
for i := 0; i < len(in); i++ {
out[i] = in[i].HeaderedEvent
if device != nil && in[i].TransactionID != nil {
@@ -295,7 +295,7 @@ func (d *Database) PurgeRoomState(
func (d *Database) WriteEvent(
ctx context.Context,
ev *gomatrixserverlib.HeaderedEvent,
- addStateEvents []gomatrixserverlib.HeaderedEvent,
+ addStateEvents []*gomatrixserverlib.HeaderedEvent,
addStateEventIDs, removeStateEventIDs []string,
transactionID *api.TransactionID, excludeFromSync bool,
) (pduPosition types.StreamPosition, returnErr error) {
@@ -332,7 +332,7 @@ func (d *Database) WriteEvent(
func (d *Database) updateRoomState(
ctx context.Context, txn *sql.Tx,
removedEventIDs []string,
- addedEvents []gomatrixserverlib.HeaderedEvent,
+ addedEvents []*gomatrixserverlib.HeaderedEvent,
pduPosition types.StreamPosition,
) error {
// remove first, then add, as we do not ever delete state, but do replace state which is a remove followed by an add.
@@ -709,14 +709,14 @@ func (d *Database) RedactEvent(ctx context.Context, redactedEventID string, reda
}
eventToRedact := redactedEvents[0].Unwrap()
redactionEvent := redactedBecause.Unwrap()
- ev, err := eventutil.RedactEvent(&redactionEvent, &eventToRedact)
+ ev, err := eventutil.RedactEvent(redactionEvent, eventToRedact)
if err != nil {
return err
}
newEvent := ev.Headered(redactedBecause.RoomVersion)
err = d.Writer.Do(nil, nil, func(txn *sql.Tx) error {
- return d.OutputEvents.UpdateEventJSON(ctx, &newEvent)
+ return d.OutputEvents.UpdateEventJSON(ctx, newEvent)
})
return err
}
@@ -809,7 +809,7 @@ func (d *Database) getJoinResponseForCompleteSync(
stateFilter *gomatrixserverlib.StateFilter,
numRecentEventsPerRoom int, device userapi.Device,
) (jr *types.JoinResponse, err error) {
- var stateEvents []gomatrixserverlib.HeaderedEvent
+ var stateEvents []*gomatrixserverlib.HeaderedEvent
stateEvents, err = d.CurrentRoomState.SelectCurrentState(ctx, txn, roomID, stateFilter)
if err != nil {
return
@@ -1180,7 +1180,7 @@ func (d *Database) getStateDeltas(
// dupe join events will result in the entire room state coming down to the client again. This is added in
// the 'state' part of the response though, so is transparent modulo bandwidth concerns as it is not added to
// the timeline.
- if membership := getMembershipFromEvent(&ev.Event, userID); membership != "" {
+ if membership := getMembershipFromEvent(ev.Event, userID); membership != "" {
if membership == gomatrixserverlib.Join {
// send full room state down instead of a delta
var s []types.StreamEvent
@@ -1264,7 +1264,7 @@ func (d *Database) getStateDeltasForFullStateSync(
for roomID, stateStreamEvents := range state {
for _, ev := range stateStreamEvents {
- if membership := getMembershipFromEvent(&ev.Event, userID); membership != "" {
+ if membership := getMembershipFromEvent(ev.Event, userID); membership != "" {
if membership != gomatrixserverlib.Join { // We've already added full state for all joined rooms above.
deltas[roomID] = stateDelta{
membership: membership,
@@ -1426,7 +1426,7 @@ func (d *Database) CleanSendToDeviceUpdates(
// There may be some overlap where events in stateEvents are already in recentEvents, so filter
// them out so we don't include them twice in the /sync response. They should be in recentEvents
// only, so clients get to the correct state once they have rolled forward.
-func removeDuplicates(stateEvents, recentEvents []gomatrixserverlib.HeaderedEvent) []gomatrixserverlib.HeaderedEvent {
+func removeDuplicates(stateEvents, recentEvents []*gomatrixserverlib.HeaderedEvent) []*gomatrixserverlib.HeaderedEvent {
for _, recentEv := range recentEvents {
if recentEv.StateKey() == nil {
continue // not a state event
@@ -1463,7 +1463,7 @@ func getMembershipFromEvent(ev *gomatrixserverlib.Event, userID string) string {
type stateDelta struct {
roomID string
- stateEvents []gomatrixserverlib.HeaderedEvent
+ stateEvents []*gomatrixserverlib.HeaderedEvent
membership string
// The PDU stream position of the latest membership event for this user, if applicable.
// Can be 0 if there is no membership event in this delta.