mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-31 18:53:10 -06:00
Remove unused SQL statements
Update comments & add TODO
This commit is contained in:
parent
c9b355836a
commit
925012a787
|
|
@ -82,6 +82,7 @@ func Context(
|
|||
ContainsURL: filter.ContainsURL,
|
||||
}
|
||||
|
||||
// TODO: Get the actual state at the last event returned by SelectContextAfterEvent
|
||||
state, _ := syncDB.CurrentState(ctx, roomID, &stateFilter, nil)
|
||||
// verify the user is allowed to see the context for this room/event
|
||||
for _, x := range state {
|
||||
|
|
@ -173,7 +174,7 @@ func parseContextParams(req *http.Request) (*gomatrixserverlib.RoomEventFilter,
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// not in the spec, but feels like a good idea to have an upper bound limit
|
||||
// NOTSPEC: feels like a good idea to have an upper bound limit
|
||||
if limit > 100 {
|
||||
limit = 100
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,5 +141,4 @@ type Database interface {
|
|||
SelectContextEvent(ctx context.Context, roomID, eventID string) (int, gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectContextBeforeEvent(ctx context.Context, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter) ([]*gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectContextAfterEvent(ctx context.Context, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter) (int, []*gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectEventIDsAfter(ctx context.Context, roomID string, id int) ([]string, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,9 +149,6 @@ const selectContextAfterEventSQL = "" +
|
|||
" AND ( $7::text[] IS NULL OR NOT(type LIKE ANY($7)) )" +
|
||||
" ORDER BY id ASC LIMIT $3"
|
||||
|
||||
const selectEventIDsAfterSQL = "" +
|
||||
"SELECT event_id FROM syncapi_output_room_events WHERE room_id = $1 AND id > $2"
|
||||
|
||||
type outputRoomEventsStatements struct {
|
||||
insertEventStmt *sql.Stmt
|
||||
selectEventsStmt *sql.Stmt
|
||||
|
|
@ -165,7 +162,6 @@ type outputRoomEventsStatements struct {
|
|||
selectContextEventStmt *sql.Stmt
|
||||
selectContextBeforeEventStmt *sql.Stmt
|
||||
selectContextAfterEventStmt *sql.Stmt
|
||||
selectEventIDsAfterStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func NewPostgresEventsTable(db *sql.DB) (tables.Events, error) {
|
||||
|
|
@ -187,7 +183,6 @@ func NewPostgresEventsTable(db *sql.DB) (tables.Events, error) {
|
|||
{&s.selectContextEventStmt, selectContextEventSQL},
|
||||
{&s.selectContextBeforeEventStmt, selectContextBeforeEventSQL},
|
||||
{&s.selectContextAfterEventStmt, selectContextAfterEventSQL},
|
||||
{&s.selectEventIDsAfterStmt, selectEventIDsAfterSQL},
|
||||
}.Prepare(db)
|
||||
}
|
||||
|
||||
|
|
@ -527,23 +522,6 @@ func (s *outputRoomEventsStatements) SelectContextAfterEvent(
|
|||
return lastID, evts, rows.Err()
|
||||
}
|
||||
|
||||
func (s *outputRoomEventsStatements) SelectEventIDsAfter(ctx context.Context, roomID string, id int) (eventIDs []string, err error) {
|
||||
rows, err := s.selectEventIDsAfterStmt.QueryContext(ctx, roomID, id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var eventID string
|
||||
if err = rows.Scan(&eventID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
eventIDs = append(eventIDs, eventID)
|
||||
}
|
||||
return eventIDs, rows.Err()
|
||||
}
|
||||
|
||||
func rowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, error) {
|
||||
var result []types.StreamEvent
|
||||
for rows.Next() {
|
||||
|
|
|
|||
|
|
@ -966,7 +966,3 @@ func (s *Database) SelectContextBeforeEvent(ctx context.Context, id int, roomID
|
|||
func (s *Database) SelectContextAfterEvent(ctx context.Context, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter) (int, []*gomatrixserverlib.HeaderedEvent, error) {
|
||||
return s.OutputEvents.SelectContextAfterEvent(ctx, nil, id, roomID, filter)
|
||||
}
|
||||
|
||||
func (s *Database) SelectEventIDsAfter(ctx context.Context, roomID string, id int) ([]string, error) {
|
||||
return s.OutputEvents.SelectEventIDsAfter(ctx, roomID, id)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,19 +62,16 @@ const selectEventsSQL = "" +
|
|||
const selectRecentEventsSQL = "" +
|
||||
"SELECT event_id, id, headered_event_json, session_id, exclude_from_sync, transaction_id FROM syncapi_output_room_events" +
|
||||
" WHERE room_id = $1 AND id > $2 AND id <= $3"
|
||||
|
||||
// WHEN, ORDER BY and LIMIT are appended by prepareWithFilters
|
||||
|
||||
const selectRecentEventsForSyncSQL = "" +
|
||||
"SELECT event_id, id, headered_event_json, session_id, exclude_from_sync, transaction_id FROM syncapi_output_room_events" +
|
||||
" WHERE room_id = $1 AND id > $2 AND id <= $3 AND exclude_from_sync = FALSE"
|
||||
|
||||
// WHEN, ORDER BY and LIMIT are appended by prepareWithFilters
|
||||
|
||||
const selectEarlyEventsSQL = "" +
|
||||
"SELECT event_id, id, headered_event_json, session_id, exclude_from_sync, transaction_id FROM syncapi_output_room_events" +
|
||||
" WHERE room_id = $1 AND id > $2 AND id <= $3"
|
||||
|
||||
// WHEN, ORDER BY and LIMIT are appended by prepareWithFilters
|
||||
|
||||
const selectMaxEventIDSQL = "" +
|
||||
|
|
@ -88,7 +85,6 @@ const selectStateInRangeSQL = "" +
|
|||
" FROM syncapi_output_room_events" +
|
||||
" WHERE (id > $1 AND id <= $2)" +
|
||||
" AND ((add_state_ids IS NOT NULL AND add_state_ids != '') OR (remove_state_ids IS NOT NULL AND remove_state_ids != ''))"
|
||||
|
||||
// WHEN, ORDER BY and LIMIT are appended by prepareWithFilters
|
||||
|
||||
const deleteEventsForRoomSQL = "" +
|
||||
|
|
@ -99,12 +95,11 @@ const selectContextEventSQL = "" +
|
|||
|
||||
const selectContextBeforeEventSQL = "" +
|
||||
"SELECT headered_event_json FROM syncapi_output_room_events WHERE room_id = $1 AND id < $2"
|
||||
// WHEN, ORDER BY and LIMIT are appended by prepareWithFilters
|
||||
|
||||
const selectContextAfterEventSQL = "" +
|
||||
"SELECT id, headered_event_json FROM syncapi_output_room_events WHERE room_id = $1 AND id > $2"
|
||||
|
||||
const selectEventIDsAfterSQL = "" +
|
||||
"SELECT event_id FROM syncapi_output_room_events WHERE room_id = $1 AND id > $2"
|
||||
// WHEN, ORDER BY and LIMIT are appended by prepareWithFilters
|
||||
|
||||
type outputRoomEventsStatements struct {
|
||||
db *sql.DB
|
||||
|
|
@ -117,7 +112,6 @@ type outputRoomEventsStatements struct {
|
|||
selectContextEventStmt *sql.Stmt
|
||||
selectContextBeforeEventStmt *sql.Stmt
|
||||
selectContextAfterEventStmt *sql.Stmt
|
||||
selectEventIDsAfterStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func NewSqliteEventsTable(db *sql.DB, streamID *streamIDStatements) (tables.Events, error) {
|
||||
|
|
@ -138,7 +132,6 @@ func NewSqliteEventsTable(db *sql.DB, streamID *streamIDStatements) (tables.Even
|
|||
{&s.selectContextEventStmt, selectContextEventSQL},
|
||||
{&s.selectContextBeforeEventStmt, selectContextBeforeEventSQL},
|
||||
{&s.selectContextAfterEventStmt, selectContextAfterEventSQL},
|
||||
{&s.selectEventIDsAfterStmt, selectEventIDsAfterSQL},
|
||||
}.Prepare(db)
|
||||
}
|
||||
|
||||
|
|
@ -563,23 +556,6 @@ func (s *outputRoomEventsStatements) SelectContextAfterEvent(
|
|||
return lastID, evts, rows.Err()
|
||||
}
|
||||
|
||||
func (s *outputRoomEventsStatements) SelectEventIDsAfter(ctx context.Context, roomID string, id int) (eventIDs []string, err error) {
|
||||
rows, err := s.selectEventIDsAfterStmt.QueryContext(ctx, roomID, id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var eventID string
|
||||
if err = rows.Scan(&eventID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
eventIDs = append(eventIDs, eventID)
|
||||
}
|
||||
return eventIDs, rows.Err()
|
||||
}
|
||||
|
||||
func unmarshalStateIDs(addIDsJSON, delIDsJSON string) (addIDs []string, delIDs []string, err error) {
|
||||
if len(addIDsJSON) > 0 {
|
||||
if err = json.Unmarshal([]byte(addIDsJSON), &addIDs); err != nil {
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ type Events interface {
|
|||
SelectContextEvent(ctx context.Context, txn *sql.Tx, roomID, eventID string) (int, gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectContextBeforeEvent(ctx context.Context, txn *sql.Tx, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter) ([]*gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectContextAfterEvent(ctx context.Context, txn *sql.Tx, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter) (int, []*gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectEventIDsAfter(ctx context.Context, roomID string, id int) ([]string, error)
|
||||
}
|
||||
|
||||
// Topology keeps track of the depths and stream positions for all events.
|
||||
|
|
|
|||
Loading…
Reference in a new issue