Unset RoomServerEvent
, since we can't be sure that Set
actually updates the cached entry (#3002)
This should deflake UTs and be more correct in terms of getting `Events`. `Events` tries to fetch the event from the cache first and may get an unredacted event from it, while it should already be redacted.
This commit is contained in:
parent
baef523cb0
commit
70322699ab
|
@ -10,6 +10,7 @@ import (
|
||||||
type RoomServerEventsCache interface {
|
type RoomServerEventsCache interface {
|
||||||
GetRoomServerEvent(eventNID types.EventNID) (*gomatrixserverlib.Event, bool)
|
GetRoomServerEvent(eventNID types.EventNID) (*gomatrixserverlib.Event, bool)
|
||||||
StoreRoomServerEvent(eventNID types.EventNID, event *gomatrixserverlib.Event)
|
StoreRoomServerEvent(eventNID types.EventNID, event *gomatrixserverlib.Event)
|
||||||
|
InvalidateRoomServerEvent(eventNID types.EventNID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Caches) GetRoomServerEvent(eventNID types.EventNID) (*gomatrixserverlib.Event, bool) {
|
func (c Caches) GetRoomServerEvent(eventNID types.EventNID) (*gomatrixserverlib.Event, bool) {
|
||||||
|
@ -19,3 +20,7 @@ func (c Caches) GetRoomServerEvent(eventNID types.EventNID) (*gomatrixserverlib.
|
||||||
func (c Caches) StoreRoomServerEvent(eventNID types.EventNID, event *gomatrixserverlib.Event) {
|
func (c Caches) StoreRoomServerEvent(eventNID types.EventNID, event *gomatrixserverlib.Event) {
|
||||||
c.RoomServerEvents.Set(int64(eventNID), event)
|
c.RoomServerEvents.Set(int64(eventNID), event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Caches) InvalidateRoomServerEvent(eventNID types.EventNID) {
|
||||||
|
c.RoomServerEvents.Unset(int64(eventNID))
|
||||||
|
}
|
||||||
|
|
|
@ -567,6 +567,7 @@ func (d *EventDatabase) events(
|
||||||
if !redactionsArePermanent {
|
if !redactionsArePermanent {
|
||||||
d.applyRedactions(results)
|
d.applyRedactions(results)
|
||||||
}
|
}
|
||||||
|
return results, nil
|
||||||
}
|
}
|
||||||
eventJSONs, err := d.EventJSONTable.BulkSelectEventJSON(ctx, txn, eventNIDs)
|
eventJSONs, err := d.EventJSONTable.BulkSelectEventJSON(ctx, txn, eventNIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -578,8 +579,9 @@ func (d *EventDatabase) events(
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, eventJSON := range eventJSONs {
|
for _, eventJSON := range eventJSONs {
|
||||||
|
redacted := gjson.GetBytes(eventJSON.EventJSON, "unsigned.redacted_because").Exists()
|
||||||
events[eventJSON.EventNID], err = gomatrixserverlib.NewEventFromTrustedJSONWithEventID(
|
events[eventJSON.EventNID], err = gomatrixserverlib.NewEventFromTrustedJSONWithEventID(
|
||||||
eventIDs[eventJSON.EventNID], eventJSON.EventJSON, false, roomInfo.RoomVersion,
|
eventIDs[eventJSON.EventNID], eventJSON.EventJSON, redacted, roomInfo.RoomVersion,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1020,7 +1022,9 @@ func (d *EventDatabase) MaybeRedactEvent(
|
||||||
return fmt.Errorf("d.RedactionsTable.MarkRedactionValidated: %w", err)
|
return fmt.Errorf("d.RedactionsTable.MarkRedactionValidated: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Cache.StoreRoomServerEvent(redactedEvent.EventNID, redactedEvent.Event)
|
// We remove the entry from the cache, as if we just "StoreRoomServerEvent", we can't be
|
||||||
|
// certain that the cached entry actually is updated, since ristretto is eventual-persistent.
|
||||||
|
d.Cache.InvalidateRoomServerEvent(redactedEvent.EventNID)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue