mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-20 12:33:09 -06:00
Minor cleanup
This commit is contained in:
parent
e779b5b3a8
commit
e7356f7e96
|
|
@ -124,6 +124,7 @@ type QueryProvider interface {
|
||||||
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
|
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExecProvider defines the interface for querys used by RunLimitedVariablesExec.
|
||||||
type ExecProvider interface {
|
type ExecProvider interface {
|
||||||
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
|
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
|
||||||
}
|
}
|
||||||
|
|
@ -157,7 +158,7 @@ func RunLimitedVariablesQuery(ctx context.Context, query string, qp QueryProvide
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunLimitedVariablesQuery split up a query with more variables than the used database can handle in multiple queries.
|
// RunLimitedVariablesExec split up a query with more variables than the used database can handle in multiple queries.
|
||||||
func RunLimitedVariablesExec(ctx context.Context, query string, qp ExecProvider, variables []interface{}, limit uint) error {
|
func RunLimitedVariablesExec(ctx context.Context, query string, qp ExecProvider, variables []interface{}, limit uint) error {
|
||||||
var start int
|
var start int
|
||||||
for start < len(variables) {
|
for start < len(variables) {
|
||||||
|
|
@ -165,7 +166,7 @@ func RunLimitedVariablesExec(ctx context.Context, query string, qp ExecProvider,
|
||||||
nextQuery := strings.Replace(query, "($1)", QueryVariadic(n), 1)
|
nextQuery := strings.Replace(query, "($1)", QueryVariadic(n), 1)
|
||||||
_, err := qp.ExecContext(ctx, nextQuery, variables[start:start+n]...)
|
_, err := qp.ExecContext(ctx, nextQuery, variables[start:start+n]...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.GetLogger(ctx).WithError(err).Error("QueryContext returned an error")
|
util.GetLogger(ctx).WithError(err).Error("ExecContext returned an error")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
start = start + n
|
start = start + n
|
||||||
|
|
|
||||||
|
|
@ -69,12 +69,11 @@ type purgeStatements struct {
|
||||||
purgeRoomAliasesStmt *sql.Stmt
|
purgeRoomAliasesStmt *sql.Stmt
|
||||||
purgeRoomStmt *sql.Stmt
|
purgeRoomStmt *sql.Stmt
|
||||||
purgeStateSnapshotEntriesStmt *sql.Stmt
|
purgeStateSnapshotEntriesStmt *sql.Stmt
|
||||||
stateBlock *StateBlockStatements
|
stateSnapshot *stateSnapshotStatements
|
||||||
stateSnapshot *StateSnapshotStatements
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func PreparePurgeStatements(db *sql.DB, stateBlock *StateBlockStatements, stateSnapshot *StateSnapshotStatements) (*purgeStatements, error) {
|
func PreparePurgeStatements(db *sql.DB, stateSnapshot *stateSnapshotStatements) (*purgeStatements, error) {
|
||||||
s := &purgeStatements{stateBlock: stateBlock, stateSnapshot: stateSnapshot}
|
s := &purgeStatements{stateSnapshot: stateSnapshot}
|
||||||
return s, sqlutil.StatementList{
|
return s, sqlutil.StatementList{
|
||||||
{&s.purgeEventJSONStmt, purgeEventJSONSQL},
|
{&s.purgeEventJSONStmt, purgeEventJSONSQL},
|
||||||
{&s.purgeEventsStmt, purgeEventsSQL},
|
{&s.purgeEventsStmt, purgeEventsSQL},
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ const bulkSelectStateBlockEntriesSQL = "" +
|
||||||
"SELECT state_block_nid, event_nids" +
|
"SELECT state_block_nid, event_nids" +
|
||||||
" FROM roomserver_state_block WHERE state_block_nid IN ($1) ORDER BY state_block_nid ASC"
|
" FROM roomserver_state_block WHERE state_block_nid IN ($1) ORDER BY state_block_nid ASC"
|
||||||
|
|
||||||
type StateBlockStatements struct {
|
type stateBlockStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
insertStateDataStmt *sql.Stmt
|
insertStateDataStmt *sql.Stmt
|
||||||
bulkSelectStateBlockEntriesStmt *sql.Stmt
|
bulkSelectStateBlockEntriesStmt *sql.Stmt
|
||||||
|
|
@ -67,8 +67,8 @@ func CreateStateBlockTable(db *sql.DB) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrepareStateBlockTable(db *sql.DB) (*StateBlockStatements, error) {
|
func PrepareStateBlockTable(db *sql.DB) (*stateBlockStatements, error) {
|
||||||
s := &StateBlockStatements{
|
s := &stateBlockStatements{
|
||||||
db: db,
|
db: db,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +78,7 @@ func PrepareStateBlockTable(db *sql.DB) (*StateBlockStatements, error) {
|
||||||
}.Prepare(db)
|
}.Prepare(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateBlockStatements) BulkInsertStateData(
|
func (s *stateBlockStatements) BulkInsertStateData(
|
||||||
ctx context.Context, txn *sql.Tx,
|
ctx context.Context, txn *sql.Tx,
|
||||||
entries types.StateEntries,
|
entries types.StateEntries,
|
||||||
) (id types.StateBlockNID, err error) {
|
) (id types.StateBlockNID, err error) {
|
||||||
|
|
@ -98,7 +98,7 @@ func (s *StateBlockStatements) BulkInsertStateData(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateBlockStatements) BulkSelectStateBlockEntries(
|
func (s *stateBlockStatements) BulkSelectStateBlockEntries(
|
||||||
ctx context.Context, txn *sql.Tx, stateBlockNIDs types.StateBlockNIDs,
|
ctx context.Context, txn *sql.Tx, stateBlockNIDs types.StateBlockNIDs,
|
||||||
) ([][]types.EventNID, error) {
|
) ([][]types.EventNID, error) {
|
||||||
intfs := make([]interface{}, len(stateBlockNIDs))
|
intfs := make([]interface{}, len(stateBlockNIDs))
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ const bulkSelectStateBlockNIDsSQL = "" +
|
||||||
const selectStateBlockNIDsForRoomNID = "" +
|
const selectStateBlockNIDsForRoomNID = "" +
|
||||||
"SELECT state_block_nids FROM roomserver_state_snapshots WHERE room_nid = $1"
|
"SELECT state_block_nids FROM roomserver_state_snapshots WHERE room_nid = $1"
|
||||||
|
|
||||||
type StateSnapshotStatements struct {
|
type stateSnapshotStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
insertStateStmt *sql.Stmt
|
insertStateStmt *sql.Stmt
|
||||||
bulkSelectStateBlockNIDsStmt *sql.Stmt
|
bulkSelectStateBlockNIDsStmt *sql.Stmt
|
||||||
|
|
@ -77,8 +77,8 @@ func CreateStateSnapshotTable(db *sql.DB) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrepareStateSnapshotTable(db *sql.DB) (*StateSnapshotStatements, error) {
|
func PrepareStateSnapshotTable(db *sql.DB) (*stateSnapshotStatements, error) {
|
||||||
s := &StateSnapshotStatements{
|
s := &stateSnapshotStatements{
|
||||||
db: db,
|
db: db,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +89,7 @@ func PrepareStateSnapshotTable(db *sql.DB) (*StateSnapshotStatements, error) {
|
||||||
}.Prepare(db)
|
}.Prepare(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateSnapshotStatements) InsertState(
|
func (s *stateSnapshotStatements) InsertState(
|
||||||
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, stateBlockNIDs types.StateBlockNIDs,
|
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, stateBlockNIDs types.StateBlockNIDs,
|
||||||
) (stateNID types.StateSnapshotNID, err error) {
|
) (stateNID types.StateSnapshotNID, err error) {
|
||||||
if stateBlockNIDs == nil {
|
if stateBlockNIDs == nil {
|
||||||
|
|
@ -108,7 +108,7 @@ func (s *StateSnapshotStatements) InsertState(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateSnapshotStatements) BulkSelectStateBlockNIDs(
|
func (s *stateSnapshotStatements) BulkSelectStateBlockNIDs(
|
||||||
ctx context.Context, txn *sql.Tx, stateNIDs []types.StateSnapshotNID,
|
ctx context.Context, txn *sql.Tx, stateNIDs []types.StateSnapshotNID,
|
||||||
) ([]types.StateBlockNIDList, error) {
|
) ([]types.StateBlockNIDList, error) {
|
||||||
nids := make([]interface{}, len(stateNIDs))
|
nids := make([]interface{}, len(stateNIDs))
|
||||||
|
|
@ -146,13 +146,13 @@ func (s *StateSnapshotStatements) BulkSelectStateBlockNIDs(
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateSnapshotStatements) BulkSelectStateForHistoryVisibility(
|
func (s *stateSnapshotStatements) BulkSelectStateForHistoryVisibility(
|
||||||
ctx context.Context, txn *sql.Tx, stateSnapshotNID types.StateSnapshotNID, domain string,
|
ctx context.Context, txn *sql.Tx, stateSnapshotNID types.StateSnapshotNID, domain string,
|
||||||
) ([]types.EventNID, error) {
|
) ([]types.EventNID, error) {
|
||||||
return nil, tables.OptimisationNotSupportedError
|
return nil, tables.OptimisationNotSupportedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateSnapshotStatements) selectStateBlockNIDsForRoomNID(
|
func (s *stateSnapshotStatements) selectStateBlockNIDsForRoomNID(
|
||||||
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID,
|
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID,
|
||||||
) ([]types.StateBlockNID, error) {
|
) ([]types.StateBlockNID, error) {
|
||||||
var res []types.StateBlockNID
|
var res []types.StateBlockNID
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ func (d *Database) prepare(db *sql.DB, writer sqlutil.Writer, cache caching.Room
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
purge, err := PreparePurgeStatements(db, stateBlock, stateSnapshot)
|
purge, err := PreparePurgeStatements(db, stateSnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue