tango-core 0.3.0

The tango schema, entities, migrations, and search contract
Documentation
use sea_orm_migration::prelude::*;

/// Parses the caller's transcript query once per call, not once per row.
///
/// `search_transcripts` was correct but paid a per-*candidate* cost that scaled
/// with the match set rather than with the page: `matched_terms` re-derived the
/// caller's lexemes with `to_tsvector` and a `to_tsquery` for every matching
/// row. Measured with EXPLAIN on a five-term query matching 5,216 cues, that
/// subplan cost 0.010 ms a row, about 50 ms of a 145 ms call.
///
/// The terms are now parsed once into `v_terms` and counted against that array,
/// which drops the per-row cost to ~0.002 ms. What is returned - columns,
/// order, the match and the count - is unchanged; `ts_headline` already ran
/// above the top-N sort, so only where `matched_terms` gets its lexemes moves.
/// On the dev corpus the five-term call measured ~145 ms to ~90 ms; a query
/// returning a page or so is unaffected either way.
#[derive(DeriveMigrationName)]
pub struct Migration;

const UP: &str = include_str!("sql/0021_transcript_search_perf.sql");

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager.get_connection().execute_unprepared(UP).await?;
        Ok(())
    }

    async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
        // A no-op, like 0010 through 0020. The reverse means reinstating the
        // slower body, which is a copy of the function 0020 already holds and
        // would be one more place for it to drift from.
        Ok(())
    }
}