aboutsummaryrefslogtreecommitdiff
path: root/syncapi/storage/postgres
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-05-14 17:30:16 +0100
committerGitHub <noreply@github.com>2020-05-14 17:30:16 +0100
commit7ca230e931faceb0b8a9e60314258d6cd59f33d4 (patch)
treee1a6ba92d289e322111a39d230ea7accc7e61c85 /syncapi/storage/postgres
parent3cb04e80042104d14ccfa162b3e40a5b08819eac (diff)
Cleanup syncapi topology logic (#1035)
* Cleanup syncapi topology logic * Variable renaming * comments
Diffstat (limited to 'syncapi/storage/postgres')
-rw-r--r--syncapi/storage/postgres/output_room_events_topology_table.go37
1 files changed, 2 insertions, 35 deletions
diff --git a/syncapi/storage/postgres/output_room_events_topology_table.go b/syncapi/storage/postgres/output_room_events_topology_table.go
index 48ebcf25..8a9cc49c 100644
--- a/syncapi/storage/postgres/output_room_events_topology_table.go
+++ b/syncapi/storage/postgres/output_room_events_topology_table.go
@@ -72,17 +72,12 @@ const selectMaxPositionInTopologySQL = "" +
"SELECT MAX(topological_position) FROM syncapi_output_room_events_topology WHERE room_id=$1" +
") ORDER BY stream_position DESC LIMIT 1"
-const selectEventIDsFromPositionSQL = "" +
- "SELECT event_id FROM syncapi_output_room_events_topology" +
- " WHERE room_id = $1 AND topological_position = $2"
-
type outputRoomEventsTopologyStatements struct {
insertEventInTopologyStmt *sql.Stmt
selectEventIDsInRangeASCStmt *sql.Stmt
selectEventIDsInRangeDESCStmt *sql.Stmt
selectPositionInTopologyStmt *sql.Stmt
selectMaxPositionInTopologyStmt *sql.Stmt
- selectEventIDsFromPositionStmt *sql.Stmt
}
func NewPostgresTopologyTable(db *sql.DB) (tables.Topology, error) {
@@ -106,9 +101,6 @@ func NewPostgresTopologyTable(db *sql.DB) (tables.Topology, error) {
if s.selectMaxPositionInTopologyStmt, err = db.Prepare(selectMaxPositionInTopologySQL); err != nil {
return nil, err
}
- if s.selectEventIDsFromPositionStmt, err = db.Prepare(selectEventIDsFromPositionSQL); err != nil {
- return nil, err
- }
return s, nil
}
@@ -127,7 +119,7 @@ func (s *outputRoomEventsTopologyStatements) InsertEventInTopology(
// given range in a given room's topological order.
// Returns an empty slice if no events match the given range.
func (s *outputRoomEventsTopologyStatements) SelectEventIDsInRange(
- ctx context.Context, txn *sql.Tx, roomID string, fromPos, toPos, toMicroPos types.StreamPosition,
+ ctx context.Context, txn *sql.Tx, roomID string, minDepth, maxDepth, maxStreamPos types.StreamPosition,
limit int, chronologicalOrder bool,
) (eventIDs []string, err error) {
// Decide on the selection's order according to whether chronological order
@@ -140,7 +132,7 @@ func (s *outputRoomEventsTopologyStatements) SelectEventIDsInRange(
}
// Query the event IDs.
- rows, err := stmt.QueryContext(ctx, roomID, fromPos, toPos, toPos, toMicroPos, limit)
+ rows, err := stmt.QueryContext(ctx, roomID, minDepth, maxDepth, maxDepth, maxStreamPos, limit)
if err == sql.ErrNoRows {
// If no event matched the request, return an empty slice.
return []string{}, nil
@@ -176,28 +168,3 @@ func (s *outputRoomEventsTopologyStatements) SelectMaxPositionInTopology(
err = s.selectMaxPositionInTopologyStmt.QueryRowContext(ctx, roomID).Scan(&pos, &spos)
return
}
-
-// SelectEventIDsFromPosition returns the IDs of all events that have a given
-// position in the topology of a given room.
-func (s *outputRoomEventsTopologyStatements) SelectEventIDsFromPosition(
- ctx context.Context, txn *sql.Tx, roomID string, pos types.StreamPosition,
-) (eventIDs []string, err error) {
- // Query the event IDs.
- rows, err := s.selectEventIDsFromPositionStmt.QueryContext(ctx, roomID, pos)
- if err == sql.ErrNoRows {
- // If no event matched the request, return an empty slice.
- return []string{}, nil
- } else if err != nil {
- return
- }
- defer common.CloseAndLogIfError(ctx, rows, "selectEventIDsFromPosition: rows.close() failed")
- // Return the IDs.
- var eventID string
- for rows.Next() {
- if err = rows.Scan(&eventID); err != nil {
- return
- }
- eventIDs = append(eventIDs, eventID)
- }
- return eventIDs, rows.Err()
-}