Refactor StoreEvent and create a new RoomDatabase interface (#2985)
This PR changes a few things: - It pulls out the creation of several NIDs from the `StoreEvent` function to make the functions more reusable - Uses more caching when using those NIDs to avoid DB round trips
This commit is contained in:
parent
e6aa0955ff
commit
ad07b169b8
31 changed files with 459 additions and 302 deletions
|
|
@ -7,6 +7,7 @@ import "github.com/matrix-org/dendrite/roomserver/types"
|
|||
type EventStateKeyCache interface {
|
||||
GetEventStateKey(eventStateKeyNID types.EventStateKeyNID) (string, bool)
|
||||
StoreEventStateKey(eventStateKeyNID types.EventStateKeyNID, eventStateKey string)
|
||||
GetEventStateKeyNID(eventStateKey string) (types.EventStateKeyNID, bool)
|
||||
}
|
||||
|
||||
func (c Caches) GetEventStateKey(eventStateKeyNID types.EventStateKeyNID) (string, bool) {
|
||||
|
|
@ -15,4 +16,23 @@ func (c Caches) GetEventStateKey(eventStateKeyNID types.EventStateKeyNID) (strin
|
|||
|
||||
func (c Caches) StoreEventStateKey(eventStateKeyNID types.EventStateKeyNID, eventStateKey string) {
|
||||
c.RoomServerStateKeys.Set(eventStateKeyNID, eventStateKey)
|
||||
c.RoomServerStateKeyNIDs.Set(eventStateKey, eventStateKeyNID)
|
||||
}
|
||||
|
||||
func (c Caches) GetEventStateKeyNID(eventStateKey string) (types.EventStateKeyNID, bool) {
|
||||
return c.RoomServerStateKeyNIDs.Get(eventStateKey)
|
||||
}
|
||||
|
||||
type EventTypeCache interface {
|
||||
GetEventTypeKey(eventType string) (types.EventTypeNID, bool)
|
||||
StoreEventTypeKey(eventTypeNID types.EventTypeNID, eventType string)
|
||||
}
|
||||
|
||||
func (c Caches) StoreEventTypeKey(eventTypeNID types.EventTypeNID, eventType string) {
|
||||
c.RoomServerEventTypeNIDs.Set(eventType, eventTypeNID)
|
||||
c.RoomServerEventTypes.Set(eventTypeNID, eventType)
|
||||
}
|
||||
|
||||
func (c Caches) GetEventTypeKey(eventType string) (types.EventTypeNID, bool) {
|
||||
return c.RoomServerEventTypeNIDs.Get(eventType)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue