mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-10 23:53:09 -06:00
Remove unused query
This commit is contained in:
parent
874489544b
commit
1c43dbcc12
|
|
@ -161,9 +161,6 @@ type Database interface {
|
||||||
|
|
||||||
IgnoresForUser(ctx context.Context, userID string) (*types.IgnoredUsers, error)
|
IgnoresForUser(ctx context.Context, userID string) (*types.IgnoredUsers, error)
|
||||||
UpdateIgnoresForUser(ctx context.Context, userID string, ignores *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
|
// 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
|
// 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.
|
// string as the membership.
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ package postgres
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
|
@ -80,13 +79,6 @@ const selectStreamToTopologicalPositionAscSQL = "" +
|
||||||
const selectStreamToTopologicalPositionDescSQL = "" +
|
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;"
|
"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 {
|
type outputRoomEventsTopologyStatements struct {
|
||||||
insertEventInTopologyStmt *sql.Stmt
|
insertEventInTopologyStmt *sql.Stmt
|
||||||
selectEventIDsInRangeASCStmt *sql.Stmt
|
selectEventIDsInRangeASCStmt *sql.Stmt
|
||||||
|
|
@ -112,7 +104,6 @@ func NewPostgresTopologyTable(db *sql.DB) (tables.Topology, error) {
|
||||||
{&s.selectMaxPositionInTopologyStmt, selectMaxPositionInTopologySQL},
|
{&s.selectMaxPositionInTopologyStmt, selectMaxPositionInTopologySQL},
|
||||||
{&s.selectStreamToTopologicalPositionAscStmt, selectStreamToTopologicalPositionAscSQL},
|
{&s.selectStreamToTopologicalPositionAscStmt, selectStreamToTopologicalPositionAscSQL},
|
||||||
{&s.selectStreamToTopologicalPositionDescStmt, selectStreamToTopologicalPositionDescSQL},
|
{&s.selectStreamToTopologicalPositionDescStmt, selectStreamToTopologicalPositionDescSQL},
|
||||||
{&s.selectTopologicalEventStmt, selectTopologicalEventSQL},
|
|
||||||
}.Prepare(db)
|
}.Prepare(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,29 +184,3 @@ func (s *outputRoomEventsTopologyStatements) SelectMaxPositionInTopology(
|
||||||
err = s.selectMaxPositionInTopologyStmt.QueryRowContext(ctx, roomID).Scan(&pos, &spos)
|
err = s.selectMaxPositionInTopologyStmt.QueryRowContext(ctx, roomID).Scan(&pos, &spos)
|
||||||
return
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -372,6 +372,7 @@ func (d *Database) WriteEvent(
|
||||||
) (pduPosition types.StreamPosition, returnErr error) {
|
) (pduPosition types.StreamPosition, returnErr error) {
|
||||||
returnErr = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
returnErr = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
var err error
|
var err error
|
||||||
|
ev.Visibility = historyVisibility
|
||||||
pos, err := d.OutputEvents.InsertEvent(
|
pos, err := d.OutputEvents.InsertEvent(
|
||||||
ctx, txn, ev, addStateEventIDs, removeStateEventIDs, transactionID, excludeFromSync, historyVisibility,
|
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)
|
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) {
|
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)
|
return d.Memberships.SelectMembershipForUser(ctx, nil, roomID, userID, pos)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ package sqlite3
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||||
|
|
@ -72,13 +71,6 @@ const selectStreamToTopologicalPositionAscSQL = "" +
|
||||||
const selectStreamToTopologicalPositionDescSQL = "" +
|
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;"
|
"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 {
|
type outputRoomEventsTopologyStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
insertEventInTopologyStmt *sql.Stmt
|
insertEventInTopologyStmt *sql.Stmt
|
||||||
|
|
@ -88,7 +80,6 @@ type outputRoomEventsTopologyStatements struct {
|
||||||
selectMaxPositionInTopologyStmt *sql.Stmt
|
selectMaxPositionInTopologyStmt *sql.Stmt
|
||||||
selectStreamToTopologicalPositionAscStmt *sql.Stmt
|
selectStreamToTopologicalPositionAscStmt *sql.Stmt
|
||||||
selectStreamToTopologicalPositionDescStmt *sql.Stmt
|
selectStreamToTopologicalPositionDescStmt *sql.Stmt
|
||||||
selectTopologicalEventStmt *sql.Stmt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSqliteTopologyTable(db *sql.DB) (tables.Topology, error) {
|
func NewSqliteTopologyTable(db *sql.DB) (tables.Topology, error) {
|
||||||
|
|
@ -107,7 +98,6 @@ func NewSqliteTopologyTable(db *sql.DB) (tables.Topology, error) {
|
||||||
{&s.selectMaxPositionInTopologyStmt, selectMaxPositionInTopologySQL},
|
{&s.selectMaxPositionInTopologyStmt, selectMaxPositionInTopologySQL},
|
||||||
{&s.selectStreamToTopologicalPositionAscStmt, selectStreamToTopologicalPositionAscSQL},
|
{&s.selectStreamToTopologicalPositionAscStmt, selectStreamToTopologicalPositionAscSQL},
|
||||||
{&s.selectStreamToTopologicalPositionDescStmt, selectStreamToTopologicalPositionDescSQL},
|
{&s.selectStreamToTopologicalPositionDescStmt, selectStreamToTopologicalPositionDescSQL},
|
||||||
{&s.selectTopologicalEventStmt, selectTopologicalEventSQL},
|
|
||||||
}.Prepare(db)
|
}.Prepare(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,28 +177,3 @@ func (s *outputRoomEventsTopologyStatements) SelectMaxPositionInTopology(
|
||||||
err = stmt.QueryRowContext(ctx, roomID).Scan(&pos, &spos)
|
err = stmt.QueryRowContext(ctx, roomID).Scan(&pos, &spos)
|
||||||
return
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,6 @@ type Topology interface {
|
||||||
SelectMaxPositionInTopology(ctx context.Context, txn *sql.Tx, roomID string) (depth types.StreamPosition, spos types.StreamPosition, err error)
|
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 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)
|
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 {
|
type CurrentRoomState interface {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue