mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 14:53:10 -06:00
Use updater txn
This commit is contained in:
parent
cc4f5fb531
commit
fafee7060f
|
|
@ -279,7 +279,7 @@ func (u *latestEventsUpdater) calculateLatest(
|
||||||
// now have entries in the previous events table. If they do then they
|
// now have entries in the previous events table. If they do then they
|
||||||
// are no longer forward extremities.
|
// are no longer forward extremities.
|
||||||
for _, l := range oldLatest {
|
for _, l := range oldLatest {
|
||||||
referenced, err := u.api.DB.EventIsReferenced(u.ctx, l.EventReference)
|
referenced, err := u.updater.IsReferenced(l.EventReference)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to retrieve event reference for %q", l.EventID)
|
logrus.WithError(err).Errorf("Failed to retrieve event reference for %q", l.EventID)
|
||||||
}
|
}
|
||||||
|
|
@ -300,7 +300,7 @@ func (u *latestEventsUpdater) calculateLatest(
|
||||||
|
|
||||||
// If the new event isn't already in the set then we'll check if it
|
// If the new event isn't already in the set then we'll check if it
|
||||||
// really should be.
|
// really should be.
|
||||||
referenced, err := u.api.DB.EventIsReferenced(u.ctx, newEvent.EventReference)
|
referenced, err := u.updater.IsReferenced(newEvent.EventReference)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to retrieve event reference for %q", newEvent.EventReference.EventID)
|
logrus.WithError(err).Errorf("Failed to retrieve event reference for %q", newEvent.EventReference.EventID)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,11 +87,6 @@ type Database interface {
|
||||||
// Lookup the event IDs for a batch of event numeric IDs.
|
// Lookup the event IDs for a batch of event numeric IDs.
|
||||||
// Returns an error if the retrieval went wrong.
|
// Returns an error if the retrieval went wrong.
|
||||||
EventIDs(ctx context.Context, eventNIDs []types.EventNID) (map[types.EventNID]string, error)
|
EventIDs(ctx context.Context, eventNIDs []types.EventNID) (map[types.EventNID]string, error)
|
||||||
// EventIsReferenced returns true if the event is referenced by another event and false otherwise.
|
|
||||||
// This is used when working out if an event is a new forward extremity or not.
|
|
||||||
EventIsReferenced(
|
|
||||||
ctx context.Context, eventRef gomatrixserverlib.EventReference,
|
|
||||||
) (bool, error)
|
|
||||||
// Look up the latest events in a room in preparation for an update.
|
// Look up the latest events in a room in preparation for an update.
|
||||||
// The RoomRecentEventsUpdater must have Commit or Rollback called on it if this doesn't return an error.
|
// The RoomRecentEventsUpdater must have Commit or Rollback called on it if this doesn't return an error.
|
||||||
// Returns the latest events in the room and the last eventID sent to the log along with an updater.
|
// Returns the latest events in the room and the last eventID sent to the log along with an updater.
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,18 @@ func (u *LatestEventsUpdater) StorePreviousEvents(eventNID types.EventNID, previ
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsReferenced implements types.RoomRecentEventsUpdater
|
||||||
|
func (u *LatestEventsUpdater) IsReferenced(eventReference gomatrixserverlib.EventReference) (bool, error) {
|
||||||
|
err := u.d.PrevEventsTable.SelectPreviousEventExists(u.ctx, u.txn, eventReference.EventID, eventReference.EventSHA256)
|
||||||
|
if err == nil {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return false, fmt.Errorf("u.d.PrevEventsTable.SelectPreviousEventExists: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// SetLatestEvents implements types.RoomRecentEventsUpdater
|
// SetLatestEvents implements types.RoomRecentEventsUpdater
|
||||||
func (u *LatestEventsUpdater) SetLatestEvents(
|
func (u *LatestEventsUpdater) SetLatestEvents(
|
||||||
roomNID types.RoomNID, latest []types.StateAtEventAndReference, lastEventNIDSent types.EventNID,
|
roomNID types.RoomNID, latest []types.StateAtEventAndReference, lastEventNIDSent types.EventNID,
|
||||||
|
|
|
||||||
|
|
@ -186,16 +186,6 @@ func (d *Database) EventIDs(
|
||||||
return d.EventsTable.BulkSelectEventID(ctx, eventNIDs)
|
return d.EventsTable.BulkSelectEventID(ctx, eventNIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) EventIsReferenced(
|
|
||||||
ctx context.Context, eventRef gomatrixserverlib.EventReference,
|
|
||||||
) (bool, error) {
|
|
||||||
err := d.PrevEventsTable.SelectPreviousEventExists(ctx, nil, eventRef.EventID, eventRef.EventSHA256)
|
|
||||||
if err != nil && err != sql.ErrNoRows {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return err != sql.ErrNoRows, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Database) EventsFromIDs(ctx context.Context, eventIDs []string) ([]types.Event, error) {
|
func (d *Database) EventsFromIDs(ctx context.Context, eventIDs []string) ([]types.Event, error) {
|
||||||
nidMap, err := d.EventNIDs(ctx, eventIDs)
|
nidMap, err := d.EventNIDs(ctx, eventIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue