Skip to content

Commit d723fd2

Browse files
committed
Merge commit '979b48ae2' into smohammed/opensearch-indexing
Signed-off-by: Salman Mohammed <smohammed@squareup.com> # Conflicts: # crates/buzz-db/src/store/search_outbox.rs
2 parents b2e9810 + 979b48a commit d723fd2

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,24 @@
2121
2222
use std::sync::atomic::{AtomicBool, Ordering};
2323

24-
use buzz_core::CommunityId;
24+
use buzz_core::{media::EDIT_GOVERNED_KINDS, CommunityId};
2525
use chrono::{DateTime, Utc};
2626
use sqlx::{PgPool, Row};
2727
use uuid::Uuid;
2828

2929
use crate::{AdmittedTx, Result};
3030

31-
/// Event kinds the search index holds; no other kind is ever indexed. Stream
32-
/// messages (9), their v2 and forum forms (40002, 40008), and workflow
33-
/// messages (45001, 45003). These are also the kinds a message edit applies
34-
/// to.
35-
pub const SEARCHABLE_KINDS: [i32; 5] = [9, 40002, 40008, 45001, 45003];
31+
/// Event kinds the search index holds; no other kind is ever indexed. They
32+
/// are the message kinds an edit can replace, so the list has one owner.
33+
pub const SEARCHABLE_KINDS: [i32; EDIT_GOVERNED_KINDS.len()] = {
34+
let mut kinds = [0; EDIT_GOVERNED_KINDS.len()];
35+
let mut i = 0;
36+
while i < kinds.len() {
37+
kinds[i] = EDIT_GOVERNED_KINDS[i] as i32;
38+
i += 1;
39+
}
40+
kinds
41+
};
3642

3743
/// A message edit: its content replaces the text of the message its first
3844
/// valid `e` tag names, in the same channel.

‎crates/buzz-db/tests/observability_source.rs‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,15 +1706,16 @@ fn events_insert_tails(source: &str) -> Vec<String> {
17061706
tails
17071707
}
17081708

1709-
/// An events insert must run both follow-ups: the push enqueue and the
1710-
/// pre-commit TTL refresh. `after_admitted_insert` does both; a writer that
1711-
/// inserts inside a savepoint calls the two halves separately.
1709+
/// An events insert must run every follow-up: the push enqueue, the search
1710+
/// outbox row and the pre-commit TTL refresh. `after_admitted_insert` does
1711+
/// all three; a writer that inserts inside a savepoint calls them separately.
17121712
///
17131713
/// Only real calls count: a hook in a comment or a string literal does not.
17141714
fn runs_event_follow_ups(function_source: &str) -> bool {
17151715
let code = mask_comments_and_literals(function_source);
17161716
code.contains("event_follow_up::after_admitted_insert(")
17171717
|| (code.contains("event_follow_up::enqueue_push_match(")
1718+
&& code.contains("search_outbox::enqueue_in_transaction(")
17181719
&& code.contains(".record_channel_event("))
17191720
}
17201721

@@ -1759,6 +1760,16 @@ pub(crate) async fn hooked_writer(tx: &mut AdmittedTx) {
17591760
.await
17601761
.expect("follow up");
17611762
}
1763+
pub(crate) async fn unsearched_writer(tx: &mut AdmittedTx) {
1764+
sqlx::query("INSERT INTO events (community_id, id) VALUES ($1, $2)")
1765+
.execute(tx.conn())
1766+
.await
1767+
.expect("write");
1768+
crate::store::event_follow_up::enqueue_push_match(tx.conn(), community, id, kind)
1769+
.await
1770+
.expect("enqueue");
1771+
tx.record_channel_event(channel, kind);
1772+
}
17621773
pub(crate) async fn savepoint_writer(tx: &mut AdmittedTx) {
17631774
sqlx::query("INSERT INTO events (community_id, id) VALUES ($1, $2)")
17641775
.execute(tx.conn())
@@ -1767,6 +1778,9 @@ pub(crate) async fn savepoint_writer(tx: &mut AdmittedTx) {
17671778
crate::store::event_follow_up::enqueue_push_match(tx.conn(), community, id, kind)
17681779
.await
17691780
.expect("enqueue");
1781+
crate::search_outbox::enqueue_in_transaction(tx, id, created_at, kind)
1782+
.await
1783+
.expect("search");
17701784
tx.record_channel_event(channel, kind);
17711785
}
17721786
pub(crate) async fn mention_writer(tx: &mut AdmittedTx) {
@@ -1900,6 +1914,7 @@ mod tests {
19001914
"pub(crate) async fn unhooked_writer(tx: &mut AdmittedTx) {",
19011915
"pub(crate) async fn quoted_writer(tx: &mut AdmittedTx) {",
19021916
"pub(crate) async fn push_only_writer(tx: &mut AdmittedTx) {",
1917+
"pub(crate) async fn unsearched_writer(tx: &mut AdmittedTx) {",
19031918
"pub(crate) async fn lowercase_writer(tx: &mut AdmittedTx) {",
19041919
"pub(crate) async fn continued_writer(tx: &mut AdmittedTx) {",
19051920
"pub(crate) async fn writer_under_doc_mention(tx: &mut AdmittedTx) {",
@@ -1915,7 +1930,7 @@ mod tests {
19151930
"pub(crate) async fn writer_after_raw_string_example(tx: &mut AdmittedTx) {",
19161931
"pub(crate) async fn writer_after_test_helper(tx: &mut AdmittedTx) {",
19171932
],
1918-
"an events insert must run the push enqueue and record the TTL refresh"
1933+
"an events insert must run the push enqueue, queue the search row and record the TTL refresh"
19191934
);
19201935
}
19211936

0 commit comments

Comments
 (0)