Skip to content

Commit 1af2e3c

Browse files
authored
Update 2836-threading.md
1 parent 4fcd3fc commit 1af2e3c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

proposals/2836-threading.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ which returns:
8383
"events": [ // the returned events, ordered by the 'closest' (by number of hops) to the anchor point.
8484
{ ... }, { ... }, { ... },
8585
],
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.
8787
// 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.
8890
}
8991
```
9092

@@ -122,6 +124,8 @@ Justifications for the response API shape are as follows:
122124
- The next batch token: Its presence indicates if there are more events and it is opaque to allow server implementations the
123125
flexibility for their own token format. There is no 'prev batch' token as it is intended for clients to request and persist
124126
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.
125129

126130
Server implementation:
127131
- Sanity check request and set defaults.
@@ -133,9 +137,17 @@ Server implementation:
133137
servers to store this lookup in a dedicated table when events are created. Apply history visibility checks to all these
134138
events and add the ones which pass into the response array, honouring the `recent_first` flag and the `limit`.
135139
- 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.
137146
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`.
139151
- When the thread DAG has been fully visited or the limit is reached, return the response array (and a `next_batch` if the request
140152
was limited). If a request comes in with the `next_batch` set to a valid value, continue walking the thread DAG from where it
141153
was previously left, ensuring that no duplicate events are sent, and that any `max_depth` or `max_breadth` are honoured

0 commit comments

Comments
 (0)