mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 21:12:45 +00:00
Use a single storage.Database interface (#978)
This commit is contained in:
parent
c30b12b5a1
commit
a202d88fe5
11 changed files with 65 additions and 204 deletions
|
@ -18,6 +18,7 @@ import (
|
|||
"context"
|
||||
"sort"
|
||||
|
||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
@ -26,7 +27,7 @@ import (
|
|||
// Returns the numeric IDs for the auth events.
|
||||
func checkAuthEvents(
|
||||
ctx context.Context,
|
||||
db RoomEventDatabase,
|
||||
db storage.Database,
|
||||
event gomatrixserverlib.HeaderedEvent,
|
||||
authEventIDs []string,
|
||||
) ([]types.EventNID, error) {
|
||||
|
@ -127,7 +128,7 @@ func (ae *authEvents) lookupEvent(typeNID types.EventTypeNID, stateKey string) *
|
|||
// loadAuthEvents loads the events needed for authentication from the supplied room state.
|
||||
func loadAuthEvents(
|
||||
ctx context.Context,
|
||||
db RoomEventDatabase,
|
||||
db storage.Database,
|
||||
needed gomatrixserverlib.StateNeeded,
|
||||
state []types.StateEntry,
|
||||
) (result authEvents, err error) {
|
||||
|
|
|
@ -23,63 +23,12 @@ import (
|
|||
"github.com/matrix-org/dendrite/common"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/roomserver/state"
|
||||
"github.com/matrix-org/dendrite/roomserver/state/database"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// A RoomEventDatabase has the storage APIs needed to store a room event.
|
||||
type RoomEventDatabase interface {
|
||||
database.RoomStateDatabase
|
||||
// Stores a matrix room event in the database
|
||||
StoreEvent(
|
||||
ctx context.Context,
|
||||
event gomatrixserverlib.Event,
|
||||
txnAndSessionID *api.TransactionID,
|
||||
authEventNIDs []types.EventNID,
|
||||
) (types.RoomNID, types.StateAtEvent, error)
|
||||
// Look up the state entries for a list of string event IDs
|
||||
// Returns an error if the there is an error talking to the database
|
||||
// Returns a types.MissingEventError if the event IDs aren't in the database.
|
||||
StateEntriesForEventIDs(
|
||||
ctx context.Context, eventIDs []string,
|
||||
) ([]types.StateEntry, error)
|
||||
// Set the state at an event.
|
||||
SetState(
|
||||
ctx context.Context,
|
||||
eventNID types.EventNID,
|
||||
stateNID types.StateSnapshotNID,
|
||||
) error
|
||||
// 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.
|
||||
// Returns the latest events in the room and the last eventID sent to the log along with an updater.
|
||||
// If this returns an error then no further action is required.
|
||||
GetLatestEventsForUpdate(
|
||||
ctx context.Context, roomNID types.RoomNID,
|
||||
) (updater types.RoomRecentEventsUpdater, err error)
|
||||
// Look up the string event IDs for a list of numeric event IDs
|
||||
EventIDs(
|
||||
ctx context.Context, eventNIDs []types.EventNID,
|
||||
) (map[types.EventNID]string, error)
|
||||
// Build a membership updater for the target user in a room.
|
||||
MembershipUpdater(
|
||||
ctx context.Context, roomID, targerUserID string,
|
||||
roomVersion gomatrixserverlib.RoomVersion,
|
||||
) (types.MembershipUpdater, error)
|
||||
// Look up event ID by transaction's info.
|
||||
// This is used to determine if the room event is processed/processing already.
|
||||
// Returns an empty string if no such event exists.
|
||||
GetTransactionEventID(
|
||||
ctx context.Context, transactionID string,
|
||||
sessionID int64, userID string,
|
||||
) (string, error)
|
||||
// Look up the room version for a given room.
|
||||
GetRoomVersionForRoom(
|
||||
ctx context.Context, roomID string,
|
||||
) (gomatrixserverlib.RoomVersion, error)
|
||||
}
|
||||
|
||||
// OutputRoomEventWriter has the APIs needed to write an event to the output logs.
|
||||
type OutputRoomEventWriter interface {
|
||||
// Write a list of events for a room
|
||||
|
@ -93,7 +42,7 @@ type OutputRoomEventWriter interface {
|
|||
// state deltas when sending to kafka streams
|
||||
func processRoomEvent(
|
||||
ctx context.Context,
|
||||
db RoomEventDatabase,
|
||||
db storage.Database,
|
||||
ow OutputRoomEventWriter,
|
||||
input api.InputRoomEvent,
|
||||
) (eventID string, err error) {
|
||||
|
@ -153,7 +102,7 @@ func processRoomEvent(
|
|||
|
||||
func calculateAndSetState(
|
||||
ctx context.Context,
|
||||
db RoomEventDatabase,
|
||||
db storage.Database,
|
||||
input api.InputRoomEvent,
|
||||
roomNID types.RoomNID,
|
||||
stateAtEvent *types.StateAtEvent,
|
||||
|
@ -184,7 +133,7 @@ func calculateAndSetState(
|
|||
|
||||
func processInviteEvent(
|
||||
ctx context.Context,
|
||||
db RoomEventDatabase,
|
||||
db storage.Database,
|
||||
ow OutputRoomEventWriter,
|
||||
input api.InputInviteEvent,
|
||||
) (err error) {
|
||||
|
|
|
@ -24,12 +24,13 @@ import (
|
|||
"github.com/Shopify/sarama"
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
// RoomserverInputAPI implements api.RoomserverInputAPI
|
||||
type RoomserverInputAPI struct {
|
||||
DB RoomEventDatabase
|
||||
DB storage.Database
|
||||
Producer sarama.SyncProducer
|
||||
// The kafkaesque topic to output new room events to.
|
||||
// This is the name used in kafka to identify the stream to write events to.
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/common"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/roomserver/state"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
|
@ -47,7 +48,7 @@ import (
|
|||
// Can only be called once at a time
|
||||
func updateLatestEvents(
|
||||
ctx context.Context,
|
||||
db RoomEventDatabase,
|
||||
db storage.Database,
|
||||
ow OutputRoomEventWriter,
|
||||
roomNID types.RoomNID,
|
||||
stateAtEvent types.StateAtEvent,
|
||||
|
@ -86,7 +87,7 @@ func updateLatestEvents(
|
|||
// when there are so many variables to pass around.
|
||||
type latestEventsUpdater struct {
|
||||
ctx context.Context
|
||||
db RoomEventDatabase
|
||||
db storage.Database
|
||||
updater types.RoomRecentEventsUpdater
|
||||
ow OutputRoomEventWriter
|
||||
roomNID types.RoomNID
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
@ -29,7 +30,7 @@ import (
|
|||
// consumers about the invites added or retired by the change in current state.
|
||||
func updateMemberships(
|
||||
ctx context.Context,
|
||||
db RoomEventDatabase,
|
||||
db storage.Database,
|
||||
updater types.RoomRecentEventsUpdater,
|
||||
removed, added []types.StateEntry,
|
||||
) ([]api.OutputEvent, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue