mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Convert room_aliases previous_events state_block and state_snapshot tables (#1064)
* Convert state_snapshot and state_block tables * Convert room_aliases and previous_events tables * Add missing table
This commit is contained in:
parent
19aa44ecae
commit
c0c5d9452a
14 changed files with 252 additions and 253 deletions
|
@ -20,6 +20,10 @@ type Database struct {
|
|||
EventStateKeysTable tables.EventStateKeys
|
||||
RoomsTable tables.Rooms
|
||||
TransactionsTable tables.Transactions
|
||||
StateSnapshotTable tables.StateSnapshot
|
||||
StateBlockTable tables.StateBlock
|
||||
RoomAliasesTable tables.RoomAliases
|
||||
PrevEventsTable tables.PreviousEvents
|
||||
}
|
||||
|
||||
// EventTypeNIDs implements state.RoomStateDatabase
|
||||
|
@ -50,6 +54,42 @@ func (d *Database) StateEntriesForEventIDs(
|
|||
return d.EventsTable.BulkSelectStateEventByID(ctx, eventIDs)
|
||||
}
|
||||
|
||||
// StateEntriesForTuples implements state.RoomStateDatabase
|
||||
func (d *Database) StateEntriesForTuples(
|
||||
ctx context.Context,
|
||||
stateBlockNIDs []types.StateBlockNID,
|
||||
stateKeyTuples []types.StateKeyTuple,
|
||||
) ([]types.StateEntryList, error) {
|
||||
return d.StateBlockTable.BulkSelectFilteredStateBlockEntries(
|
||||
ctx, stateBlockNIDs, stateKeyTuples,
|
||||
)
|
||||
}
|
||||
|
||||
// AddState implements input.EventDatabase
|
||||
func (d *Database) AddState(
|
||||
ctx context.Context,
|
||||
roomNID types.RoomNID,
|
||||
stateBlockNIDs []types.StateBlockNID,
|
||||
state []types.StateEntry,
|
||||
) (stateNID types.StateSnapshotNID, err error) {
|
||||
err = internal.WithTransaction(d.DB, func(txn *sql.Tx) error {
|
||||
if len(state) > 0 {
|
||||
var stateBlockNID types.StateBlockNID
|
||||
stateBlockNID, err = d.StateBlockTable.BulkInsertStateData(ctx, txn, state)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stateBlockNIDs = append(stateBlockNIDs[:len(stateBlockNIDs):len(stateBlockNIDs)], stateBlockNID)
|
||||
}
|
||||
stateNID, err = d.StateSnapshotTable.InsertState(ctx, txn, roomNID, stateBlockNIDs)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// EventNIDs implements query.RoomserverQueryAPIDatabase
|
||||
func (d *Database) EventNIDs(
|
||||
ctx context.Context, eventIDs []string,
|
||||
|
@ -150,6 +190,20 @@ func (d *Database) LatestEventIDs(
|
|||
return
|
||||
}
|
||||
|
||||
// StateBlockNIDs implements state.RoomStateDatabase
|
||||
func (d *Database) StateBlockNIDs(
|
||||
ctx context.Context, stateNIDs []types.StateSnapshotNID,
|
||||
) ([]types.StateBlockNIDList, error) {
|
||||
return d.StateSnapshotTable.BulkSelectStateBlockNIDs(ctx, stateNIDs)
|
||||
}
|
||||
|
||||
// StateEntries implements state.RoomStateDatabase
|
||||
func (d *Database) StateEntries(
|
||||
ctx context.Context, stateBlockNIDs []types.StateBlockNID,
|
||||
) ([]types.StateEntryList, error) {
|
||||
return d.StateBlockTable.BulkSelectStateBlockEntries(ctx, stateBlockNIDs)
|
||||
}
|
||||
|
||||
func (d *Database) GetRoomVersionForRoom(
|
||||
ctx context.Context, roomID string,
|
||||
) (gomatrixserverlib.RoomVersion, error) {
|
||||
|
@ -166,6 +220,33 @@ func (d *Database) GetRoomVersionForRoomNID(
|
|||
)
|
||||
}
|
||||
|
||||
// SetRoomAlias implements alias.RoomserverAliasAPIDB
|
||||
func (d *Database) SetRoomAlias(ctx context.Context, alias string, roomID string, creatorUserID string) error {
|
||||
return d.RoomAliasesTable.InsertRoomAlias(ctx, alias, roomID, creatorUserID)
|
||||
}
|
||||
|
||||
// GetRoomIDForAlias implements alias.RoomserverAliasAPIDB
|
||||
func (d *Database) GetRoomIDForAlias(ctx context.Context, alias string) (string, error) {
|
||||
return d.RoomAliasesTable.SelectRoomIDFromAlias(ctx, alias)
|
||||
}
|
||||
|
||||
// GetAliasesForRoomID implements alias.RoomserverAliasAPIDB
|
||||
func (d *Database) GetAliasesForRoomID(ctx context.Context, roomID string) ([]string, error) {
|
||||
return d.RoomAliasesTable.SelectAliasesFromRoomID(ctx, roomID)
|
||||
}
|
||||
|
||||
// GetCreatorIDForAlias implements alias.RoomserverAliasAPIDB
|
||||
func (d *Database) GetCreatorIDForAlias(
|
||||
ctx context.Context, alias string,
|
||||
) (string, error) {
|
||||
return d.RoomAliasesTable.SelectCreatorIDFromAlias(ctx, alias)
|
||||
}
|
||||
|
||||
// RemoveRoomAlias implements alias.RoomserverAliasAPIDB
|
||||
func (d *Database) RemoveRoomAlias(ctx context.Context, alias string) error {
|
||||
return d.RoomAliasesTable.DeleteRoomAlias(ctx, alias)
|
||||
}
|
||||
|
||||
// Events implements input.EventDatabase
|
||||
func (d *Database) Events(
|
||||
ctx context.Context, eventNIDs []types.EventNID,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue