Skip to content

Commit a948a43

Browse files
TheSentinel454Elrondclaude
committed
revert(db): keep idx_events_community_deleted
Production reader stats show the index scanned continuously, so the drop comes out of this PR. The replaceable head and supersede fix stays. Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Luke Tornquist <[email protected]>
1 parent a4d6254 commit a948a43

6 files changed

Lines changed: 4 additions & 177 deletions

File tree

‎crates/buzz-db/src/runtime/migration.rs‎

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -898,21 +898,10 @@ mod postgres_tests {
898898
let mut migrations: Vec<_> = MIGRATOR.iter().collect();
899899
migrations.sort_by_key(|migration| migration.version);
900900

901-
assert_eq!(migrations.len(), 84);
901+
assert_eq!(migrations.len(), 83);
902902
for (index, migration) in migrations.iter().enumerate() {
903903
assert_eq!(migration.version, (index + 1) as i64);
904904
}
905-
// Unused events index (0084): a plain, bounded drop, because a
906-
// partitioned index cannot be dropped CONCURRENTLY. The desired schema
907-
// no longer declares it.
908-
assert_eq!(migrations[83].version, 84);
909-
let drop_deleted = strip_sql_comments(migrations[83].sql.as_str());
910-
assert!(drop_deleted.contains("SET LOCAL lock_timeout = '1s';"));
911-
assert!(drop_deleted.contains("SET LOCAL statement_timeout = '5s';"));
912-
assert!(drop_deleted.contains("DROP INDEX IF EXISTS public.idx_events_community_deleted;"));
913-
assert!(!drop_deleted.contains("CONCURRENTLY"));
914-
assert!(!crate::test_support::desired_state_schema_sql()
915-
.contains("idx_events_community_deleted"));
916905
assert!(migrations[79]
917906
.sql
918907
.as_str()
@@ -3089,22 +3078,6 @@ mod postgres_tests {
30893078
"idx_channels_listed_name parity mismatch: update \
30903079
schema/tables/public/channels.sql to match migration 0083"
30913080
);
3092-
// `events` index set, by name and definition: the desired state and the
3093-
// migrations must agree on which indexes the parent carries (0084 drops
3094-
// idx_events_community_deleted from both).
3095-
let desired_events_indexes = index_shapes(&desired, "events").await;
3096-
assert!(
3097-
!desired_events_indexes
3098-
.iter()
3099-
.any(|(name, _, _)| name == "idx_events_community_deleted"),
3100-
"desired state must not declare idx_events_community_deleted"
3101-
);
3102-
assert_eq!(
3103-
desired_events_indexes,
3104-
index_shapes(&migrated, "events").await,
3105-
"events index parity mismatch: update schema/tables/public/events.sql to match \
3106-
the migrations"
3107-
);
31083081
assert_eq!(
31093082
events_key_defs(&desired).await,
31103083
events_key_defs(&migrated).await,

‎crates/buzz-db/src/runtime/tests.rs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4212,9 +4212,6 @@ mod thread_window_postgres_tests;
42124212
#[path = "tests/listed_channel_name_postgres_tests.rs"]
42134213
mod listed_channel_name_postgres_tests;
42144214

4215-
#[path = "tests/events_deleted_index_drop_postgres_tests.rs"]
4216-
mod events_deleted_index_drop_postgres_tests;
4217-
42184215
#[path = "tests/reader_pool_postgres_tests.rs"]
42194216
mod reader_pool_postgres_tests;
42204217

‎crates/buzz-db/src/runtime/tests/events_deleted_index_drop_postgres_tests.rs‎

Lines changed: 0 additions & 108 deletions
This file was deleted.

‎crates/buzz-db/src/runtime/tests/listed_channel_name_postgres_tests.rs‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -505,18 +505,6 @@ async fn ledger_version(pool: &PgPool) -> i64 {
505505
.expect("read migration ledger")
506506
}
507507

508-
/// Whether migration `version` is recorded as applied. Later migrations also
509-
/// run, so the ledger's maximum is not 0083's.
510-
async fn applied(pool: &PgPool, version: i64) -> bool {
511-
sqlx::query_scalar(
512-
"SELECT EXISTS (SELECT 1 FROM _sqlx_migrations WHERE version = $1 AND success)",
513-
)
514-
.bind(version)
515-
.fetch_one(pool)
516-
.await
517-
.expect("read migration ledger")
518-
}
519-
520508
async fn index_oid(pool: &PgPool) -> Option<i64> {
521509
sqlx::query_scalar("SELECT to_regclass('public.idx_channels_listed_name')::oid::bigint")
522510
.fetch_one(pool)
@@ -568,7 +556,7 @@ async fn migration_schema_listed_name_index_needs_the_renames_then_builds_inline
568556
migration::run_migrations(&pool)
569557
.await
570558
.expect("migrate a populated table after the renames");
571-
assert!(applied(&pool, BEFORE_INDEX + 1).await, "0083 is applied");
559+
assert_eq!(ledger_version(&pool).await, BEFORE_INDEX + 1);
572560
let mut expected = vec![
573561
(kept, "square-ios".to_owned()),
574562
renamed(newer, "Square-iOS"),
@@ -645,6 +633,6 @@ async fn migration_schema_listed_name_index_validates_a_prebuild() {
645633
.await
646634
.expect("accept the prebuild without waiting for channel writers");
647635
writer.rollback().await.unwrap();
648-
assert!(applied(&pool, BEFORE_INDEX + 1).await, "0083 is applied");
636+
assert_eq!(ledger_version(&pool).await, BEFORE_INDEX + 1);
649637
assert_eq!(index_oid(&pool).await, oid, "the prebuild is not replaced");
650638
}

‎migrations/0084_drop_events_community_deleted_index.sql‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎schema/tables/public/events.sql‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ CREATE INDEX idx_events_community_pubkey_kind_created
5151
ON events (community_id, pubkey, kind, created_at DESC, id);
5252
CREATE INDEX idx_events_community_kind_created
5353
ON events (community_id, kind, created_at DESC, id);
54+
CREATE INDEX idx_events_community_deleted ON events (community_id, deleted_at);
5455
-- Addressable (replaceable) and NIP-33 parameterized lookups.
5556
CREATE INDEX idx_events_addressable
5657
ON events (community_id, kind, pubkey, channel_id, deleted_at);

0 commit comments

Comments
 (0)