Skip to content

Commit 1ebdd0e

Browse files
committed
refactor(relay): simplify newer thread window routing and parse tests
Signed-off-by: Liching Li <liching@squareup.com>
1 parent c3b64cb commit 1ebdd0e

2 files changed

Lines changed: 14 additions & 26 deletions

File tree

‎crates/buzz-core/src/thread_window.rs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ mod tests {
278278
f["before_id"] = json!("a".repeat(64));
279279
assert!(Request::parse(&f).is_err(), "{f}");
280280
}
281-
// A newer window continues only with since/after_id.
281+
// A newer window rejects until/before_id and needs both since and after_id.
282282
for (key, value) in [
283283
("since", json!(1)),
284284
("after_id", json!("ab".repeat(32))),
@@ -292,11 +292,6 @@ mod tests {
292292
}
293293
let mut f = filter();
294294
f["direction"] = json!("newer");
295-
f["until"] = json!(1);
296-
f["before_id"] = json!("ab".repeat(32));
297-
assert!(Request::parse(&f).is_err(), "{f}");
298-
f.as_object_mut().unwrap().remove("until");
299-
f.as_object_mut().unwrap().remove("before_id");
300295
f["since"] = json!(1);
301296
f["after_id"] = json!("AB".repeat(32));
302297
let request = Request::parse(&f).unwrap();

‎crates/buzz-db/src/store/thread_window.rs‎

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,32 +225,25 @@ impl Db {
225225
budget: &mut ScanBudget,
226226
) -> Result<(ThreadWindow, ReadSession)> {
227227
let cursor = request.cursor.as_ref().map(cursor_key).transpose()?;
228-
let (path, predicate) = match (request.direction, &cursor) {
229-
// Even a freshly checked replica can miss a committed reply and
230-
// sign a false exhausted newer page.
231-
(Direction::Newer, _) => ("thread_window_newer", None),
232-
(Direction::Older, Some(_)) => (
233-
"thread_window_cursor",
234-
Some(RoutePredicate::from_channel_cursor(
235-
request.channel,
236-
&cursor,
237-
)),
238-
),
239-
(Direction::Older, None) => ("thread_window_head", Some(RoutePredicate::Bounded)),
228+
let path = match (request.direction, cursor.is_some()) {
229+
(Direction::Newer, _) => "thread_window_newer",
230+
(Direction::Older, true) => "thread_window_cursor",
231+
(Direction::Older, false) => "thread_window_head",
240232
};
241-
let decision = match predicate {
242-
Some(predicate) => Some(
233+
// Even a freshly checked replica can miss a committed reply and sign
234+
// a false exhausted newer page.
235+
let decision = if request.direction == Direction::Older {
236+
Some(
243237
self.route_read(
244238
path,
245-
predicate,
239+
RoutePredicate::from_channel_cursor(request.channel, &cursor),
246240
crate::observability::ReaderOperation::SubscriptionHistory,
247241
)
248242
.await?,
249-
),
250-
None => {
251-
Self::record_route(path, "writer", "newer_direction");
252-
None
253-
}
243+
)
244+
} else {
245+
Self::record_route(path, "writer", "newer_direction");
246+
None
254247
};
255248
if let Some(RouteDecision::Replica(mut tx, _, reason)) = decision {
256249
let result = async {

0 commit comments

Comments
 (0)