Server-side aggregation of m.replace relationships #845

Open
opened 2025-06-02 16:17:43 +00:00 by Jade · 3 comments
Owner

https://spec.matrix.org/v1.14/client-server-api/#server-side-aggregation-of-mreplace-relationships

Doesn't seem to be happening in my testing. May require additional database index for a performant lookup. Not sure what to do about historic events in that case - running index creation would be expensive, can add an admin command and a one-time-use flag.

https://spec.matrix.org/v1.14/client-server-api/#server-side-aggregation-of-mreplace-relationships Doesn't seem to be happening in my testing. May require additional database index for a performant lookup. Not sure what to do about historic events in that case - running index creation would be expensive, can add an admin command and a one-time-use flag.
Author
Owner

This looks like a similar codepath:

.get("m.relations")


Perhaps it should be generic?

This looks like a similar codepath: https://forgejo.ellis.link/continuwuation/continuwuity/src/commit/d8311a5ff672fdc4729d956af5e3af8646b0670d/src/service/rooms/threads/mod.rs#L81 Perhaps it should be generic?
Author
Owner

Compare synapse to continuwuity:

{
  "content": {
    "body": "lucifer: you wanna get back on the setup right now?",
    "format": "org.matrix.custom.html",
    "formatted_body": "<a href=\"https://matrix.to/#/@lucifer:chatbrainz.org\">lucifer</a>: you wanna get back on the setup right now?",
    "m.mentions": {
      "user_ids": [
        "@lucifer:chatbrainz.org"
      ]
    },
    "msgtype": "m.text"
  },
  "origin_server_ts": 1748886535809,
  "room_id": "!hyuEWFORfWYLZitABm:chatbrainz.org",
  "sender": "@holycow23:matrix.org",
  "type": "m.room.message",
  "unsigned": {
    "age": 297063,
    "m.relations": {
      "m.replace": {
        "content": {
          "body": "* lucifer: can you help me with the setup right now?",
          "format": "org.matrix.custom.html",
          "formatted_body": "* <a href=\"https://matrix.to/#/@lucifer:chatbrainz.org\">lucifer</a>: can you help me with the setup right now?",
          "m.mentions": {},
          "m.new_content": {
            "body": "lucifer: can you help me with the setup right now?",
            "format": "org.matrix.custom.html",
            "formatted_body": "<a href=\"https://matrix.to/#/@lucifer:chatbrainz.org\">lucifer</a>: can you help me with the setup right now?",
            "m.mentions": {
              "user_ids": [
                "@lucifer:chatbrainz.org"
              ]
            },
            "msgtype": "m.text"
          },
          "m.relates_to": {
            "event_id": "$bBeKTvoBrsQkuQoUQKLNhWlVOQqeI4cC-cnjf0AF0VE",
            "rel_type": "m.replace"
          },
          "msgtype": "m.text"
        },
        "origin_server_ts": 1748886559974,
        "room_id": "!hyuEWFORfWYLZitABm:chatbrainz.org",
        "sender": "@holycow23:matrix.org",
        "type": "m.room.message",
        "unsigned": {
          "age": 272898
        },
        "event_id": "$G6Cv_ZVo9SwcrKmjwKLQ_iA-DQvjiLpkjtIEA1nFu9k",
        "user_id": "@holycow23:matrix.org",
        "age": 272898
      }
    }
  },
  "event_id": "$bBeKTvoBrsQkuQoUQKLNhWlVOQqeI4cC-cnjf0AF0VE",
  "user_id": "@holycow23:matrix.org",
  "age": 297063
}
{
  "content": {
    "body": "lucifer: you wanna get back on the setup right now?",
    "format": "org.matrix.custom.html",
    "formatted_body": "<a href=\"https://matrix.to/#/@lucifer:chatbrainz.org\">lucifer</a>: you wanna get back on the setup right now?",
    "m.mentions": {
      "user_ids": [
        "@lucifer:chatbrainz.org"
      ]
    },
    "msgtype": "m.text"
  },
  "event_id": "$bBeKTvoBrsQkuQoUQKLNhWlVOQqeI4cC-cnjf0AF0VE",
  "origin_server_ts": 1748886535809,
  "room_id": "!hyuEWFORfWYLZitABm:chatbrainz.org",
  "sender": "@holycow23:matrix.org",
  "type": "m.room.message",
  "unsigned": {
    "age": 349692
  }
}
Compare synapse to continuwuity: ```JSON { "content": { "body": "lucifer: you wanna get back on the setup right now?", "format": "org.matrix.custom.html", "formatted_body": "<a href=\"https://matrix.to/#/@lucifer:chatbrainz.org\">lucifer</a>: you wanna get back on the setup right now?", "m.mentions": { "user_ids": [ "@lucifer:chatbrainz.org" ] }, "msgtype": "m.text" }, "origin_server_ts": 1748886535809, "room_id": "!hyuEWFORfWYLZitABm:chatbrainz.org", "sender": "@holycow23:matrix.org", "type": "m.room.message", "unsigned": { "age": 297063, "m.relations": { "m.replace": { "content": { "body": "* lucifer: can you help me with the setup right now?", "format": "org.matrix.custom.html", "formatted_body": "* <a href=\"https://matrix.to/#/@lucifer:chatbrainz.org\">lucifer</a>: can you help me with the setup right now?", "m.mentions": {}, "m.new_content": { "body": "lucifer: can you help me with the setup right now?", "format": "org.matrix.custom.html", "formatted_body": "<a href=\"https://matrix.to/#/@lucifer:chatbrainz.org\">lucifer</a>: can you help me with the setup right now?", "m.mentions": { "user_ids": [ "@lucifer:chatbrainz.org" ] }, "msgtype": "m.text" }, "m.relates_to": { "event_id": "$bBeKTvoBrsQkuQoUQKLNhWlVOQqeI4cC-cnjf0AF0VE", "rel_type": "m.replace" }, "msgtype": "m.text" }, "origin_server_ts": 1748886559974, "room_id": "!hyuEWFORfWYLZitABm:chatbrainz.org", "sender": "@holycow23:matrix.org", "type": "m.room.message", "unsigned": { "age": 272898 }, "event_id": "$G6Cv_ZVo9SwcrKmjwKLQ_iA-DQvjiLpkjtIEA1nFu9k", "user_id": "@holycow23:matrix.org", "age": 272898 } } }, "event_id": "$bBeKTvoBrsQkuQoUQKLNhWlVOQqeI4cC-cnjf0AF0VE", "user_id": "@holycow23:matrix.org", "age": 297063 } ``` ```json { "content": { "body": "lucifer: you wanna get back on the setup right now?", "format": "org.matrix.custom.html", "formatted_body": "<a href=\"https://matrix.to/#/@lucifer:chatbrainz.org\">lucifer</a>: you wanna get back on the setup right now?", "m.mentions": { "user_ids": [ "@lucifer:chatbrainz.org" ] }, "msgtype": "m.text" }, "event_id": "$bBeKTvoBrsQkuQoUQKLNhWlVOQqeI4cC-cnjf0AF0VE", "origin_server_ts": 1748886535809, "room_id": "!hyuEWFORfWYLZitABm:chatbrainz.org", "sender": "@holycow23:matrix.org", "type": "m.room.message", "unsigned": { "age": 349692 } } ```
Author
Owner

Two plans for implementing this:

Add a other function like the thread one that inserts in the database. Disadvantages is that it grows the database, doesn't work for historic events and might get funky with switching impls.

Use

tofrom_relation: Arc<Map>,

which is used for the relations endpoint. May slow down timeline slightly as it's not indexed by type or order, and we'd have to iterate through, filter and find the 'max' event every time we get the PDU ready for the client. However, will work for historic events as long as that doesn't have any bugs.

Probs the second one is best.

I think fixing this will fix room list message previews in EX, not 100% sure on that though.

Two plans for implementing this: Add a other function like the thread one that inserts in the database. Disadvantages is that it grows the database, doesn't work for historic events and might get funky with switching impls. Use https://forgejo.ellis.link/continuwuation/continuwuity/src/commit/d8311a5ff672fdc4729d956af5e3af8646b0670d/src/service/rooms/pdu_metadata/data.rs#L26 which is used for the relations endpoint. May slow down timeline slightly as it's not indexed by type or order, and we'd have to iterate through, filter and find the 'max' event every time we get the PDU ready for the client. However, will work for historic events as long as that doesn't have any bugs. Probs the second one is best. I think fixing this will fix room list message previews in EX, not 100% sure on that though.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: continuwuation/continuwuity#845
No description provided.