aboutsummaryrefslogtreecommitdiff
path: root/roomserver/storage/shared
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-05-27 09:36:09 +0100
committerGitHub <noreply@github.com>2020-05-27 09:36:09 +0100
commitc0c5d9452a24dcecb9378dd147f48098f18cce04 (patch)
tree2255ada17f142d18da643bd371a0c5f2bc8bd75d /roomserver/storage/shared
parent19aa44ecaef70a2be7294e8ad738467da41d1f2e (diff)
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
Diffstat (limited to 'roomserver/storage/shared')
-rw-r--r--roomserver/storage/shared/storage.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go
index 814b6e81..29c6f73e 100644
--- a/roomserver/storage/shared/storage.go
+++ b/roomserver/storage/shared/storage.go
@@ -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,