Remove unused query

This commit is contained in:
Till Faelligen 2022-07-19 12:36:23 +02:00
parent 874489544b
commit 1c43dbcc12
5 changed files with 1 additions and 78 deletions

View file

@ -161,9 +161,6 @@ type Database interface {
IgnoresForUser(ctx context.Context, userID string) (*types.IgnoredUsers, error)
UpdateIgnoresForUser(ctx context.Context, userID string, ignores *types.IgnoredUsers) error
// SelectTopologicalEvent selects an event before and including the given position by eventType and roomID. Returns the found event and the topology token.
// If not event was found, returns nil and sql.ErrNoRows.
SelectTopologicalEvent(ctx context.Context, topologicalPosition int, eventType, roomID string) (*gomatrixserverlib.HeaderedEvent, types.TopologyToken, error)
// SelectMembershipForUser returns the membership of the user before and including the given position. If no membership can be found
// returns "leave", the topological position and no error. If an error occurs, other than sql.ErrNoRows, returns that and an empty
// string as the membership.

View file

@ -17,7 +17,6 @@ package postgres
import (
"context"
"database/sql"
"encoding/json"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
@ -80,13 +79,6 @@ const selectStreamToTopologicalPositionAscSQL = "" +
const selectStreamToTopologicalPositionDescSQL = "" +
"SELECT topological_position FROM syncapi_output_room_events_topology WHERE room_id = $1 AND stream_position <= $2 ORDER BY topological_position DESC LIMIT 1;"
const selectTopologicalEventSQL = "" +
"SELECT se.headered_event_json, st.topological_position, st.stream_position " +
" FROM syncapi_output_room_events_topology st " +
" JOIN syncapi_output_room_events se ON se.event_id = st.event_id " +
" WHERE st.room_id = $1 AND st.topological_position <= $2 AND se.type = $3 " +
" ORDER BY st.topological_position DESC LIMIT 1"
type outputRoomEventsTopologyStatements struct {
insertEventInTopologyStmt *sql.Stmt
selectEventIDsInRangeASCStmt *sql.Stmt
@ -112,7 +104,6 @@ func NewPostgresTopologyTable(db *sql.DB) (tables.Topology, error) {
{&s.selectMaxPositionInTopologyStmt, selectMaxPositionInTopologySQL},
{&s.selectStreamToTopologicalPositionAscStmt, selectStreamToTopologicalPositionAscSQL},
{&s.selectStreamToTopologicalPositionDescStmt, selectStreamToTopologicalPositionDescSQL},
{&s.selectTopologicalEventStmt, selectTopologicalEventSQL},
}.Prepare(db)
}
@ -193,29 +184,3 @@ func (s *outputRoomEventsTopologyStatements) SelectMaxPositionInTopology(
err = s.selectMaxPositionInTopologyStmt.QueryRowContext(ctx, roomID).Scan(&pos, &spos)
return
}
// SelectTopologicalEvent selects an event before and including the given position by eventType and roomID. Returns the found event and the topology token.
// If not event was found, returns nil and sql.ErrNoRows.
func (s *outputRoomEventsTopologyStatements) SelectTopologicalEvent(
ctx context.Context, txn *sql.Tx, topologicalPosition int, eventType, roomID string,
) (*gomatrixserverlib.HeaderedEvent, types.TopologyToken, error) {
var (
eventBytes []byte
token types.TopologyToken
)
err := sqlutil.TxStmtContext(ctx, txn, s.selectTopologicalEventStmt).
QueryRowContext(ctx, roomID, topologicalPosition, eventType).
Scan(&eventBytes, &token.Depth, &token.PDUPosition)
if err != nil {
return nil, types.TopologyToken{}, err
}
var res *gomatrixserverlib.HeaderedEvent
if err = json.Unmarshal(eventBytes, &res); err != nil {
return nil, types.TopologyToken{}, err
}
return res, token, nil
}

View file

@ -372,6 +372,7 @@ func (d *Database) WriteEvent(
) (pduPosition types.StreamPosition, returnErr error) {
returnErr = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
var err error
ev.Visibility = historyVisibility
pos, err := d.OutputEvents.InsertEvent(
ctx, txn, ev, addStateEventIDs, removeStateEventIDs, transactionID, excludeFromSync, historyVisibility,
)
@ -1074,10 +1075,6 @@ func (d *Database) MaxStreamPositionForPresence(ctx context.Context) (types.Stre
return d.Presence.GetMaxPresenceID(ctx, nil)
}
func (d *Database) SelectTopologicalEvent(ctx context.Context, topologicalPosition int, eventType, roomID string) (*gomatrixserverlib.HeaderedEvent, types.TopologyToken, error) {
return d.Topology.SelectTopologicalEvent(ctx, nil, topologicalPosition, eventType, roomID)
}
func (d *Database) SelectMembershipForUser(ctx context.Context, roomID, userID string, pos int64) (membership string, topologicalPos int, err error) {
return d.Memberships.SelectMembershipForUser(ctx, nil, roomID, userID, pos)
}

View file

@ -17,7 +17,6 @@ package sqlite3
import (
"context"
"database/sql"
"encoding/json"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/syncapi/storage/tables"
@ -72,13 +71,6 @@ const selectStreamToTopologicalPositionAscSQL = "" +
const selectStreamToTopologicalPositionDescSQL = "" +
"SELECT topological_position FROM syncapi_output_room_events_topology WHERE room_id = $1 AND stream_position <= $2 ORDER BY topological_position DESC LIMIT 1;"
const selectTopologicalEventSQL = "" +
"SELECT headered_event_json, topological_position, stream_position " +
" FROM syncapi_output_room_events_topology " +
" JOIN syncapi_output_room_events ON syncapi_output_room_events.event_id = syncapi_output_room_events_topology.event_id " +
" WHERE syncapi_output_room_events_topology.room_id = $1 AND topological_position <= $2 AND type = $3 " +
" ORDER BY topological_position DESC LIMIT 1"
type outputRoomEventsTopologyStatements struct {
db *sql.DB
insertEventInTopologyStmt *sql.Stmt
@ -88,7 +80,6 @@ type outputRoomEventsTopologyStatements struct {
selectMaxPositionInTopologyStmt *sql.Stmt
selectStreamToTopologicalPositionAscStmt *sql.Stmt
selectStreamToTopologicalPositionDescStmt *sql.Stmt
selectTopologicalEventStmt *sql.Stmt
}
func NewSqliteTopologyTable(db *sql.DB) (tables.Topology, error) {
@ -107,7 +98,6 @@ func NewSqliteTopologyTable(db *sql.DB) (tables.Topology, error) {
{&s.selectMaxPositionInTopologyStmt, selectMaxPositionInTopologySQL},
{&s.selectStreamToTopologicalPositionAscStmt, selectStreamToTopologicalPositionAscSQL},
{&s.selectStreamToTopologicalPositionDescStmt, selectStreamToTopologicalPositionDescSQL},
{&s.selectTopologicalEventStmt, selectTopologicalEventSQL},
}.Prepare(db)
}
@ -187,28 +177,3 @@ func (s *outputRoomEventsTopologyStatements) SelectMaxPositionInTopology(
err = stmt.QueryRowContext(ctx, roomID).Scan(&pos, &spos)
return
}
// SelectTopologicalEvent selects an event before and including the given position by eventType and roomID. Returns the found event and the topology token.
// If not event was found, returns nil and sql.ErrNoRows.
func (s *outputRoomEventsTopologyStatements) SelectTopologicalEvent(
ctx context.Context, txn *sql.Tx, topologicalPosition int, eventType, roomID string,
) (*gomatrixserverlib.HeaderedEvent, types.TopologyToken, error) {
var (
eventBytes []byte
token types.TopologyToken
)
err := sqlutil.TxStmtContext(ctx, txn, s.selectTopologicalEventStmt).
QueryRowContext(ctx, roomID, topologicalPosition, eventType).
Scan(&eventBytes, &token.Depth, &token.PDUPosition)
if err != nil {
return nil, types.TopologyToken{}, err
}
var res *gomatrixserverlib.HeaderedEvent
if err = json.Unmarshal(eventBytes, &res); err != nil {
return nil, types.TopologyToken{}, err
}
return res, token, nil
}

View file

@ -93,7 +93,6 @@ type Topology interface {
SelectMaxPositionInTopology(ctx context.Context, txn *sql.Tx, roomID string) (depth types.StreamPosition, spos types.StreamPosition, err error)
// SelectStreamToTopologicalPosition converts a stream position to a topological position by finding the nearest topological position in the room.
SelectStreamToTopologicalPosition(ctx context.Context, txn *sql.Tx, roomID string, streamPos types.StreamPosition, forward bool) (topoPos types.StreamPosition, err error)
SelectTopologicalEvent(ctx context.Context, txn *sql.Tx, topologicalPosition int, eventType, roomID string) (*gomatrixserverlib.HeaderedEvent, types.TopologyToken, error)
}
type CurrentRoomState interface {