Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose rejection_reason and internal_metadata #15

Merged
merged 2 commits into from
Feb 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ struct RoomRow {
sender: String,
state_group: Option<i64>,
json: serde_json::Value,
internal_metadata: serde_json::Value,
ts: i64,
edges: Vec<String>,
stream_ordering: i32,
rejection_reason: Option<String>,
}

#[derive(Serialize)]
Expand Down Expand Up @@ -97,8 +99,9 @@ impl RouteHandler for RoomHandler {
DatabaseConnection::Postgres(_) => {
conn.query(
r#"
SELECT event_id, events.type, state_key, depth, sender, state_group,
json, origin_server_ts, stream_ordering,
SELECT event_id, events.type, state_events.state_key, depth, sender, state_group,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also disambiguating state_key while I'm here, per matrix-org/synapse#11497

json, internal_metadata, origin_server_ts, stream_ordering,
rejections.reason,
array(
SELECT prev_event_id FROM event_edges
WHERE is_state = false and event_id = events.event_id
Expand All @@ -107,6 +110,7 @@ impl RouteHandler for RoomHandler {
INNER JOIN event_json USING (event_id)
LEFT JOIN state_events USING (event_id)
LEFT JOIN event_to_state_groups USING (event_id)
LEFT JOIN rejections USING (event_id)
WHERE events.room_id = $1 AND stream_ordering <= $2::bigint
ORDER BY stream_ordering DESC
LIMIT $3::int
Expand All @@ -118,12 +122,14 @@ impl RouteHandler for RoomHandler {
DatabaseConnection::Sqlite(_) => {
let mut events = conn.query(
r#"
SELECT event_id, events.type, state_key, depth, sender, state_group, json, origin_server_ts,
stream_ordering
SELECT event_id, events.type, state_events.state_key, depth, sender, state_group,
json, internal_metadata, origin_server_ts, stream_ordering,
rejections.reason
FROM events
JOIN event_json USING (event_id)
LEFT JOIN state_events USING (event_id)
LEFT JOIN event_to_state_groups USING (event_id)
LEFT JOIN rejections USING (event_id)
WHERE events.room_id = $1 AND stream_ordering <= $2::bigint
ORDER BY stream_ordering DESC
LIMIT $3::int
Expand Down Expand Up @@ -171,7 +177,7 @@ impl RouteHandler for StateHandler {
SELECT prev_state_group FROM state_group_edges e, state s
WHERE s.state_group = e.state_group
)
SELECT event_id, es.type, state_key, ej.json, e.depth
SELECT event_id, es.type, es.state_key, ej.json, e.depth
FROM state_groups_state
NATURAL JOIN (
SELECT type, state_key, max(state_group) as state_group FROM state_groups_state
Expand Down Expand Up @@ -200,7 +206,7 @@ impl RouteHandler for StateHandler {
fn parse_event_row(row: &mut DbRow<'_>) -> RoomRow {
// the postgres variant returns the event edges as an array
let edges = match row {
DbRow::Postgres(ref mut pgrow) => pgrow.get(9),
DbRow::Postgres(ref mut pgrow) => pgrow.get(11),
_ => Vec::new(),
};

Expand All @@ -213,8 +219,11 @@ fn parse_event_row(row: &mut DbRow<'_>) -> RoomRow {
state_group: row.get(5),
json: serde_json::from_str(&row.get::<String>(6))
.expect("json was not json"),
ts: row.get(7),
stream_ordering: row.get(8),
internal_metadata: serde_json::from_str(&row.get::<String>(7))
.expect("internal_metadata was not json"),
ts: row.get(8),
stream_ordering: row.get(9),
rejection_reason: row.get(10),
edges: edges,
};
}
Expand Down