You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/2836-threading.md
+15-3Lines changed: 15 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -83,8 +83,10 @@ which returns:
83
83
"events": [ // the returned events, ordered by the 'closest' (by number of hops) to the anchor point.
84
84
{ ... }, { ... }, { ... },
85
85
],
86
-
"next_batch": "opaque_string" // A token which can be used to retrieve the next batch of events, if the response is limited.
86
+
"next_batch": "opaque_string", // A token which can be used to retrieve the next batch of events, if the response is limited.
87
87
// Optional: can be omitted if the server doesn't implement threaded pagination.
88
+
"limited": true|false // True if there are more events to return because the `limit` was reached. Servers are not obligated
89
+
// to return more events, see if the next_batch token is provided or not.
88
90
}
89
91
```
90
92
@@ -122,6 +124,8 @@ Justifications for the response API shape are as follows:
122
124
- The next batch token: Its presence indicates if there are more events and it is opaque to allow server implementations the
123
125
flexibility for their own token format. There is no 'prev batch' token as it is intended for clients to request and persist
124
126
the data on their side rather than page through results like traditional pagination.
127
+
- The limited flag: Required in order to distinguish between "no more events" and "more events but I don't allow pagination".
128
+
This additional state cannot be accurately represented by an empty `next_batch` token.
125
129
126
130
Server implementation:
127
131
- Sanity check request and set defaults.
@@ -133,9 +137,17 @@ Server implementation:
133
137
servers to store this lookup in a dedicated table when events are created. Apply history visibility checks to all these
134
138
events and add the ones which pass into the response array, honouring the `recent_first` flag and the `limit`.
135
139
- Begin to walk the thread DAG in the `direction` specified, either depth or breadth first according to the `depth_first` flag,
136
-
honouring the `limit`, `max_depth` and `max_breadth` values. For events at the same level, honour the `recent_first` flag.
140
+
honouring the `limit`, `max_depth` and `max_breadth` values according to the following rules:
141
+
* If the response array is `>= limit`, stop.
142
+
* If already processed event, skip.
143
+
* Check how deep the event is compared to `event_id`, does it *exceed* (greater than) `max_depth`? If yes, skip.
144
+
* Check what number child this event is (ordered by `recent_first`) compared to its parent, does it *exceed* (greater than) `max_breadth`? If yes, skip.
145
+
* Process the event.
137
146
If the event has been added to the response array already, do not include it a second time. If an event fails history visibiilty
138
-
checks, do not add it to the response array and do not follow any references it may have.
147
+
checks, do not add it to the response array and do not follow any references it may have. This algorithm bounds an infinite DAG
148
+
into a "window" (governed by `max_depth` and `max_breadth`) and serves up to `limit` events at a time, until the entire window
149
+
has been served. Critically, the `limit`_has not been reached_ when the algorithm hits a `max_depth` or `max_breadth`, it is only
150
+
reached when the response array is `>= limit`.
139
151
- When the thread DAG has been fully visited or the limit is reached, return the response array (and a `next_batch` if the request
140
152
was limited). If a request comes in with the `next_batch` set to a valid value, continue walking the thread DAG from where it
141
153
was previously left, ensuring that no duplicate events are sent, and that any `max_depth` or `max_breadth` are honoured
0 commit comments