Minor cleanup

This commit is contained in:
Till Faelligen 2022-12-22 14:52:56 +01:00
parent e779b5b3a8
commit e7356f7e96
No known key found for this signature in database
GPG key ID: ACCDC9606D472758
5 changed files with 19 additions and 19 deletions

View file

@ -124,6 +124,7 @@ type QueryProvider interface {
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}
// ExecProvider defines the interface for querys used by RunLimitedVariablesExec.
type ExecProvider interface {
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
}
// 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 {
var start int
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)
_, err := qp.ExecContext(ctx, nextQuery, variables[start:start+n]...)
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
}
start = start + n

View file

@ -69,12 +69,11 @@ type purgeStatements struct {
purgeRoomAliasesStmt *sql.Stmt
purgeRoomStmt *sql.Stmt
purgeStateSnapshotEntriesStmt *sql.Stmt
stateBlock *StateBlockStatements
stateSnapshot *StateSnapshotStatements
stateSnapshot *stateSnapshotStatements
}
func PreparePurgeStatements(db *sql.DB, stateBlock *StateBlockStatements, stateSnapshot *StateSnapshotStatements) (*purgeStatements, error) {
s := &purgeStatements{stateBlock: stateBlock, stateSnapshot: stateSnapshot}
func PreparePurgeStatements(db *sql.DB, stateSnapshot *stateSnapshotStatements) (*purgeStatements, error) {
s := &purgeStatements{stateSnapshot: stateSnapshot}
return s, sqlutil.StatementList{
{&s.purgeEventJSONStmt, purgeEventJSONSQL},
{&s.purgeEventsStmt, purgeEventsSQL},

View file

@ -56,7 +56,7 @@ const bulkSelectStateBlockEntriesSQL = "" +
"SELECT state_block_nid, event_nids" +
" 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
insertStateDataStmt *sql.Stmt
bulkSelectStateBlockEntriesStmt *sql.Stmt
@ -67,8 +67,8 @@ func CreateStateBlockTable(db *sql.DB) error {
return err
}
func PrepareStateBlockTable(db *sql.DB) (*StateBlockStatements, error) {
s := &StateBlockStatements{
func PrepareStateBlockTable(db *sql.DB) (*stateBlockStatements, error) {
s := &stateBlockStatements{
db: db,
}
@ -78,7 +78,7 @@ func PrepareStateBlockTable(db *sql.DB) (*StateBlockStatements, error) {
}.Prepare(db)
}
func (s *StateBlockStatements) BulkInsertStateData(
func (s *stateBlockStatements) BulkInsertStateData(
ctx context.Context, txn *sql.Tx,
entries types.StateEntries,
) (id types.StateBlockNID, err error) {
@ -98,7 +98,7 @@ func (s *StateBlockStatements) BulkInsertStateData(
return
}
func (s *StateBlockStatements) BulkSelectStateBlockEntries(
func (s *stateBlockStatements) BulkSelectStateBlockEntries(
ctx context.Context, txn *sql.Tx, stateBlockNIDs types.StateBlockNIDs,
) ([][]types.EventNID, error) {
intfs := make([]interface{}, len(stateBlockNIDs))

View file

@ -65,7 +65,7 @@ const bulkSelectStateBlockNIDsSQL = "" +
const selectStateBlockNIDsForRoomNID = "" +
"SELECT state_block_nids FROM roomserver_state_snapshots WHERE room_nid = $1"
type StateSnapshotStatements struct {
type stateSnapshotStatements struct {
db *sql.DB
insertStateStmt *sql.Stmt
bulkSelectStateBlockNIDsStmt *sql.Stmt
@ -77,8 +77,8 @@ func CreateStateSnapshotTable(db *sql.DB) error {
return err
}
func PrepareStateSnapshotTable(db *sql.DB) (*StateSnapshotStatements, error) {
s := &StateSnapshotStatements{
func PrepareStateSnapshotTable(db *sql.DB) (*stateSnapshotStatements, error) {
s := &stateSnapshotStatements{
db: db,
}
@ -89,7 +89,7 @@ func PrepareStateSnapshotTable(db *sql.DB) (*StateSnapshotStatements, error) {
}.Prepare(db)
}
func (s *StateSnapshotStatements) InsertState(
func (s *stateSnapshotStatements) InsertState(
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, stateBlockNIDs types.StateBlockNIDs,
) (stateNID types.StateSnapshotNID, err error) {
if stateBlockNIDs == nil {
@ -108,7 +108,7 @@ func (s *StateSnapshotStatements) InsertState(
return
}
func (s *StateSnapshotStatements) BulkSelectStateBlockNIDs(
func (s *stateSnapshotStatements) BulkSelectStateBlockNIDs(
ctx context.Context, txn *sql.Tx, stateNIDs []types.StateSnapshotNID,
) ([]types.StateBlockNIDList, error) {
nids := make([]interface{}, len(stateNIDs))
@ -146,13 +146,13 @@ func (s *StateSnapshotStatements) BulkSelectStateBlockNIDs(
return results, nil
}
func (s *StateSnapshotStatements) BulkSelectStateForHistoryVisibility(
func (s *stateSnapshotStatements) BulkSelectStateForHistoryVisibility(
ctx context.Context, txn *sql.Tx, stateSnapshotNID types.StateSnapshotNID, domain string,
) ([]types.EventNID, error) {
return nil, tables.OptimisationNotSupportedError
}
func (s *StateSnapshotStatements) selectStateBlockNIDsForRoomNID(
func (s *stateSnapshotStatements) selectStateBlockNIDsForRoomNID(
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID,
) ([]types.StateBlockNID, error) {
var res []types.StateBlockNID

View file

@ -197,7 +197,7 @@ func (d *Database) prepare(db *sql.DB, writer sqlutil.Writer, cache caching.Room
if err != nil {
return err
}
purge, err := PreparePurgeStatements(db, stateBlock, stateSnapshot)
purge, err := PreparePurgeStatements(db, stateSnapshot)
if err != nil {
return err
}