GetJoinedHosts from federation server db

This commit is contained in:
Anant Prakash 2018-08-02 22:58:41 +05:30
parent dc89e04e7d
commit b500f2bfb6
No known key found for this signature in database
GPG key ID: C5D399F626523045
2 changed files with 24 additions and 2 deletions

View file

@ -97,10 +97,22 @@ func (s *joinedHostsStatements) deleteJoinedHosts(
return err return err
} }
func (s *joinedHostsStatements) selectJoinedHosts( func (s *joinedHostsStatements) selectJoinedHostsWithTx(
ctx context.Context, txn *sql.Tx, roomID string, ctx context.Context, txn *sql.Tx, roomID string,
) ([]types.JoinedHost, error) { ) ([]types.JoinedHost, error) {
stmt := common.TxStmt(txn, s.selectJoinedHostsStmt) stmt := common.TxStmt(txn, s.selectJoinedHostsStmt)
return joinedHostsFromStmt(ctx, stmt, roomID)
}
func (s *joinedHostsStatements) selectJoinedHosts(
ctx context.Context, roomID string,
) ([]types.JoinedHost, error) {
return joinedHostsFromStmt(ctx, s.selectJoinedHostsStmt, roomID)
}
func joinedHostsFromStmt(
ctx context.Context, stmt *sql.Stmt, roomID string,
) ([]types.JoinedHost, error) {
rows, err := stmt.QueryContext(ctx, roomID) rows, err := stmt.QueryContext(ctx, roomID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -118,5 +130,6 @@ func (s *joinedHostsStatements) selectJoinedHosts(
ServerName: gomatrixserverlib.ServerName(serverName), ServerName: gomatrixserverlib.ServerName(serverName),
}) })
} }
return result, nil return result, nil
} }

View file

@ -92,7 +92,7 @@ func (d *Database) UpdateRoom(
} }
} }
joinedHosts, err = d.selectJoinedHosts(ctx, txn, roomID) joinedHosts, err = d.selectJoinedHostsWithTx(ctx, txn, roomID)
if err != nil { if err != nil {
return err return err
} }
@ -110,3 +110,12 @@ func (d *Database) UpdateRoom(
}) })
return return
} }
// GetJoinedHosts returns the currently joined hosts for room,
// as known to federationserver.
// Returns an error if something goes wrong.
func (d *Database) GetJoinedHosts(
ctx context.Context, roomID string,
) ([]types.JoinedHost, error) {
return d.selectJoinedHosts(ctx, roomID)
}