|
42 | 42 | from frozendict import frozendict
|
43 | 43 |
|
44 | 44 | from twisted.internet import defer
|
| 45 | +from tabulate import tabulate |
45 | 46 |
|
46 | 47 | from synapse.api.filtering import Filter
|
47 | 48 | from synapse.events import EventBase
|
@@ -748,21 +749,21 @@ def _f(txn):
|
748 | 749 | "get_room_event_before_stream_ordering", _f
|
749 | 750 | )
|
750 | 751 |
|
751 |
| - async def get_room_events_max_id(self, room_id: Optional[str] = None) -> str: |
| 752 | + async def get_room_events_max_id(self, room_id: Optional[str] = None) -> RoomStreamToken: |
752 | 753 | """Returns the current token for rooms stream.
|
753 | 754 |
|
754 | 755 | By default, it returns the current global stream token. Specifying a
|
755 | 756 | `room_id` causes it to return the current room specific topological
|
756 | 757 | token.
|
757 | 758 | """
|
758 |
| - token = self.get_room_max_stream_ordering() |
| 759 | + stream_ordering = self.get_room_max_stream_ordering() |
759 | 760 | if room_id is None:
|
760 |
| - return "s%d" % (token,) |
| 761 | + return RoomStreamToken(None, stream_ordering) |
761 | 762 | else:
|
762 | 763 | topo = await self.db_pool.runInteraction(
|
763 | 764 | "_get_max_topological_txn", self._get_max_topological_txn, room_id
|
764 | 765 | )
|
765 |
| - return "t%d-%d" % (topo, token) |
| 766 | + return RoomStreamToken(topo, stream_ordering) |
766 | 767 |
|
767 | 768 | def get_stream_id_for_event_txn(
|
768 | 769 | self,
|
@@ -808,6 +809,44 @@ async def get_topological_token_for_event(self, event_id: str) -> RoomStreamToke
|
808 | 809 | )
|
809 | 810 | return RoomStreamToken(row["topological_ordering"], row["stream_ordering"])
|
810 | 811 |
|
| 812 | + async def asdf_get_debug_events_in_room_ordered_by_depth(self, room_id: str) -> Any: |
| 813 | + """Gets the topological token in a room after or at the given stream |
| 814 | + ordering. |
| 815 | +
|
| 816 | + Args: |
| 817 | + room_id |
| 818 | + """ |
| 819 | + sql = ( |
| 820 | + "SELECT depth, stream_ordering, type, state_key, event_id FROM events" |
| 821 | + " WHERE events.room_id = ?" |
| 822 | + " ORDER BY depth DESC, stream_ordering DESC;" |
| 823 | + ) |
| 824 | + rows = await self.db_pool.execute( |
| 825 | + "asdf_get_debug_events_in_room_ordered_by_depth", None, sql, room_id |
| 826 | + ) |
| 827 | + |
| 828 | + headers = ["depth", "stream_ordering", "type", "state_key", "event_id"] |
| 829 | + return tabulate(rows, headers=headers) |
| 830 | + |
| 831 | + async def asdf_get_debug_events_in_room_ordered_by_stream_ordering(self, room_id: str) -> Any: |
| 832 | + """Gets the topological token in a room after or at the given stream |
| 833 | + ordering. |
| 834 | +
|
| 835 | + Args: |
| 836 | + room_id |
| 837 | + """ |
| 838 | + sql = ( |
| 839 | + "SELECT depth, stream_ordering, type, state_key, event_id FROM events" |
| 840 | + " WHERE events.room_id = ?" |
| 841 | + " ORDER BY stream_ordering DESC, depth DESC;" |
| 842 | + ) |
| 843 | + rows = await self.db_pool.execute( |
| 844 | + "asdf_get_debug_events_in_room_ordered_by_depth", None, sql, room_id |
| 845 | + ) |
| 846 | + |
| 847 | + headers = ["depth", "stream_ordering", "type", "state_key", "event_id"] |
| 848 | + return tabulate(rows, headers=headers) |
| 849 | + |
811 | 850 | async def get_current_topological_token(self, room_id: str, stream_key: int) -> int:
|
812 | 851 | """Gets the topological token in a room after or at the given stream
|
813 | 852 | ordering.
|
|
0 commit comments