mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 21:32:46 +00:00
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
|
@ -140,10 +140,10 @@ const bulkSelectEventIDSQL = "" +
|
|||
"SELECT event_nid, event_id FROM roomserver_events WHERE event_nid = ANY($1)"
|
||||
|
||||
const bulkSelectEventNIDSQL = "" +
|
||||
"SELECT event_id, event_nid FROM roomserver_events WHERE event_id = ANY($1)"
|
||||
"SELECT event_id, event_nid, room_nid FROM roomserver_events WHERE event_id = ANY($1)"
|
||||
|
||||
const bulkSelectUnsentEventNIDSQL = "" +
|
||||
"SELECT event_id, event_nid FROM roomserver_events WHERE event_id = ANY($1) AND sent_to_output = FALSE"
|
||||
"SELECT event_id, event_nid, room_nid FROM roomserver_events WHERE event_id = ANY($1) AND sent_to_output = FALSE"
|
||||
|
||||
const selectMaxEventDepthSQL = "" +
|
||||
"SELECT COALESCE(MAX(depth) + 1, 0) FROM roomserver_events WHERE event_nid = ANY($1)"
|
||||
|
@ -520,20 +520,20 @@ func (s *eventStatements) BulkSelectEventID(ctx context.Context, txn *sql.Tx, ev
|
|||
|
||||
// BulkSelectEventNIDs returns a map from string event ID to numeric event ID.
|
||||
// If an event ID is not in the database then it is omitted from the map.
|
||||
func (s *eventStatements) BulkSelectEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string) (map[string]types.EventNID, error) {
|
||||
func (s *eventStatements) BulkSelectEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string) (map[string]types.EventMetadata, error) {
|
||||
return s.bulkSelectEventNID(ctx, txn, eventIDs, false)
|
||||
}
|
||||
|
||||
// BulkSelectEventNIDs returns a map from string event ID to numeric event ID
|
||||
// only for events that haven't already been sent to the roomserver output.
|
||||
// If an event ID is not in the database then it is omitted from the map.
|
||||
func (s *eventStatements) BulkSelectUnsentEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string) (map[string]types.EventNID, error) {
|
||||
func (s *eventStatements) BulkSelectUnsentEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string) (map[string]types.EventMetadata, error) {
|
||||
return s.bulkSelectEventNID(ctx, txn, eventIDs, true)
|
||||
}
|
||||
|
||||
// bulkSelectEventNIDs returns a map from string event ID to numeric event ID.
|
||||
// If an event ID is not in the database then it is omitted from the map.
|
||||
func (s *eventStatements) bulkSelectEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string, onlyUnsent bool) (map[string]types.EventNID, error) {
|
||||
func (s *eventStatements) bulkSelectEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string, onlyUnsent bool) (map[string]types.EventMetadata, error) {
|
||||
var stmt *sql.Stmt
|
||||
if onlyUnsent {
|
||||
stmt = sqlutil.TxStmt(txn, s.bulkSelectUnsentEventNIDStmt)
|
||||
|
@ -545,14 +545,18 @@ func (s *eventStatements) bulkSelectEventNID(ctx context.Context, txn *sql.Tx, e
|
|||
return nil, err
|
||||
}
|
||||
defer internal.CloseAndLogIfError(ctx, rows, "bulkSelectEventNID: rows.close() failed")
|
||||
results := make(map[string]types.EventNID, len(eventIDs))
|
||||
results := make(map[string]types.EventMetadata, len(eventIDs))
|
||||
var eventID string
|
||||
var eventNID int64
|
||||
var roomNID int64
|
||||
for rows.Next() {
|
||||
if err = rows.Scan(&eventID, &eventNID); err != nil {
|
||||
if err = rows.Scan(&eventID, &eventNID, &roomNID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
results[eventID] = types.EventNID(eventNID)
|
||||
results[eventID] = types.EventMetadata{
|
||||
EventNID: types.EventNID(eventNID),
|
||||
RoomNID: types.RoomNID(roomNID),
|
||||
}
|
||||
}
|
||||
return results, rows.Err()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue