rename types to be better self-documenting

This commit is contained in:
Brandon Thomas committed 2024-01-22 20:54:19 -05:00
1 parent 0ee62b64fe
commit ea85dbc6e6
10 files changed
+62 -62

No files matched your search

@@ -15,7 +15,7 @@ pub async fn get_tts_model_for_enqueue_inference_migration(
mysql_connection: &mut PoolConnection<MySql>,
can_see_deleted: bool,
use_weights_table: bool,
) -> AnyhowResult<Option<TtsModelForEnqueueInferenceMigration>> {
) -> AnyhowResult<Option<TtsModelForEnqueueInferenceMigrationWrapper>> {
// NB: This is temporary migration code as we switch from the `tts_models` table to the `model_weights` table.
if use_weights_table {
let token = ModelWeightToken::new_from_str(token);
@@ -26,7 +26,7 @@ pub async fn get_tts_model_for_enqueue_inference_migration(
mysql_connection
).await?;
Ok(maybe_model.map(|model| TtsModelForEnqueueInferenceMigration::ModelWeight(model)))
Ok(maybe_model.map(|model| TtsModelForEnqueueInferenceMigrationWrapper::ModelWeight(model)))
} else {
@@ -36,21 +36,21 @@ pub async fn get_tts_model_for_enqueue_inference_migration(
mysql_connection
).await?;
Ok(maybe_model.map(|model| TtsModelForEnqueueInferenceMigration::LegacyTts(model)))
Ok(maybe_model.map(|model| TtsModelForEnqueueInferenceMigrationWrapper::LegacyTts(model)))
}
}
/// Union over the legacy table and the new table to support an easier migration.
/// This enum can hold a record of either type and present a unified accessor interface.
#[derive(Clone, Serialize, Deserialize)]
pub enum TtsModelForEnqueueInferenceMigration {
pub enum TtsModelForEnqueueInferenceMigrationWrapper {
/// Old type from the `tts_models` table, on the way out
LegacyTts(TtsModelRecord),
/// New type, replacing the `tts_models` table.
ModelWeight(ModelWeightForLegacyTtsEnqueue),
}
impl TtsModelForEnqueueInferenceMigration {
impl TtsModelForEnqueueInferenceMigrationWrapper {
pub fn token(&self) -> &str {
match self {
Self::LegacyTts(ref model) => model.model_token.as_str(),
@@ -16,7 +16,7 @@ use tokens::tokens::users::UserToken;
pub async fn get_tts_model_for_run_inference_migration(
tts_model_token: &str,
mysql_pool: &MySqlPool,
) -> Result<Option<TtsModelForRunInferenceMigration>, TtsModelForInferenceError> {
) -> Result<Option<TtsModelForRunInferenceMigrationWrapper>, TtsModelForInferenceError> {
// NB: This is temporary migration code as we switch from the `tts_models` table to the `model_weights` table.
if tts_model_token.starts_with(ModelWeightToken::token_prefix()) {
let token = ModelWeightToken::new_from_str(tts_model_token);
@@ -26,7 +26,7 @@ pub async fn get_tts_model_for_run_inference_migration(
mysql_pool
).await?;
Ok(maybe_model.map(|model| TtsModelForRunInferenceMigration::ModelWeight(model)))
Ok(maybe_model.map(|model| TtsModelForRunInferenceMigrationWrapper::ModelWeight(model)))
} else {
let maybe_model = get_tts_model_for_inference_improved(
@@ -34,7 +34,7 @@ pub async fn get_tts_model_for_run_inference_migration(
&tts_model_token,
).await?;
Ok(maybe_model.map(|model| TtsModelForRunInferenceMigration::LegacyTts(model)))
Ok(maybe_model.map(|model| TtsModelForRunInferenceMigrationWrapper::LegacyTts(model)))
}
}
@@ -42,14 +42,14 @@ pub async fn get_tts_model_for_run_inference_migration(
/// Union over the legacy table and the new table to support an easier migration.
/// This enum can hold a record of either type and present a unified accessor interface.
#[derive(Clone)]
pub enum TtsModelForRunInferenceMigration {
pub enum TtsModelForRunInferenceMigrationWrapper {
/// Old type from the `tts_models` table, on the way out
LegacyTts(TtsModelForInferenceRecord),
/// New type, replacing the `tts_models` table.
ModelWeight(ModelWeightForLegacyTtsInference),
}
impl TtsModelForRunInferenceMigration {
impl TtsModelForRunInferenceMigrationWrapper {
pub fn token(&self) -> &str {
match self {
Self::LegacyTts(ref model) => model.model_token.as_str(),
@@ -18,7 +18,7 @@ pub async fn get_tts_model_info_migration(
mysql_connection: &mut PoolConnection<MySql>,
can_see_deleted: bool,
use_weights_table: bool,
) -> AnyhowResult<Option<TtsModelInfoMigration>> {
) -> AnyhowResult<Option<TtsModelInfoMigrationWrapper>> {
// NB: This is temporary migration code as we switch from the `tts_models` table to the `model_weights` table.
if use_weights_table {
let token = ModelWeightToken::new_from_str(token);
@@ -29,7 +29,7 @@ pub async fn get_tts_model_info_migration(
mysql_connection
).await?;
Ok(maybe_model.map(|model| TtsModelInfoMigration::ModelWeight(model)))
Ok(maybe_model.map(|model| TtsModelInfoMigrationWrapper::ModelWeight(model)))
} else {
let maybe_model = get_tts_model_by_token_using_connection(
@@ -38,21 +38,21 @@ pub async fn get_tts_model_info_migration(
mysql_connection
).await?;
Ok(maybe_model.map(|model| TtsModelInfoMigration::LegacyTts(model)))
Ok(maybe_model.map(|model| TtsModelInfoMigrationWrapper::LegacyTts(model)))
}
}
/// Union over the legacy table and the new table to support an easier migration.
/// This enum can hold a record of either type and present a unified accessor interface.
#[derive(Clone, Serialize, Deserialize)]
pub enum TtsModelInfoMigration {
pub enum TtsModelInfoMigrationWrapper {
/// Old type from the `tts_models` table, on the way out
LegacyTts(TtsModelRecord),
/// New type, replacing the `tts_models` table.
ModelWeight(ModelWeightForLegacyTtsInfo),
}
impl TtsModelInfoMigration {
impl TtsModelInfoMigrationWrapper {
pub fn token(&self) -> &str {
match self {
Self::LegacyTts(ref model) => model.model_token.as_str(),
@@ -13,14 +13,14 @@ use mysql_queries::queries::tts::tts_models::list_tts_models::{list_tts_models_w
pub async fn list_tts_models_for_migration(
mysql_connection: &mut PoolConnection<MySql>,
use_weights_table: bool,
) -> AnyhowResult<Vec<TtsModelForList>> {
) -> AnyhowResult<Vec<TtsModelForListMigrationWrapper>> {
// NB: This is temporary migration code as we switch from the `tts_models` table to the `model_weights` table.
if use_weights_table {
let models = list_model_weights_for_text_to_speech(
mysql_connection).await?;
Ok(models.into_iter()
.map(|model| TtsModelForList::ModelWeight(model))
.map(|model| TtsModelForListMigrationWrapper::ModelWeight(model))
.collect())
} else {
@@ -28,7 +28,7 @@ pub async fn list_tts_models_for_migration(
mysql_connection, None, false).await?;
Ok(models.into_iter()
.map(|model| TtsModelForList::LegacyTts(model))
.map(|model| TtsModelForListMigrationWrapper::LegacyTts(model))
.collect())
}
}
@@ -36,120 +36,120 @@ pub async fn list_tts_models_for_migration(
/// Union over the legacy table and the new table to support an easier migration.
/// This enum can hold a record of either type and present a unified accessor interface.
#[derive(Clone)]
pub enum TtsModelForList {
pub enum TtsModelForListMigrationWrapper {
/// Old type from the `tts_models` table, on the way out
LegacyTts(TtsModelRecordForList),
/// New type, replacing the `tts_models` table.
ModelWeight(ModelWeightForTts),
}
impl TtsModelForList {
impl TtsModelForListMigrationWrapper {
pub fn token(&self) -> &str {
match self {
TtsModelForList::LegacyTts(ref model) => model.model_token.as_str(),
TtsModelForList::ModelWeight(ref model) => model.token.as_str(),
TtsModelForListMigrationWrapper::LegacyTts(ref model) => model.model_token.as_str(),
TtsModelForListMigrationWrapper::ModelWeight(ref model) => model.token.as_str(),
}
}
pub fn title(&self) -> &str {
match self {
TtsModelForList::LegacyTts(ref model) => &model.title,
TtsModelForList::ModelWeight(ref model) => &model.title,
TtsModelForListMigrationWrapper::LegacyTts(ref model) => &model.title,
TtsModelForListMigrationWrapper::ModelWeight(ref model) => &model.title,
}
}
pub fn ietf_language_tag(&self) -> &str {
match self {
TtsModelForList::LegacyTts(ref model) => &model.ietf_language_tag,
TtsModelForList::ModelWeight(ref model) => &model.ietf_language_tag,
TtsModelForListMigrationWrapper::LegacyTts(ref model) => &model.ietf_language_tag,
TtsModelForListMigrationWrapper::ModelWeight(ref model) => &model.ietf_language_tag,
}
}
pub fn ietf_primary_language_subtag(&self) -> &str {
match self {
TtsModelForList::LegacyTts(ref model) => &model.ietf_primary_language_subtag,
TtsModelForList::ModelWeight(ref model) => &model.ietf_primary_language_subtag,
TtsModelForListMigrationWrapper::LegacyTts(ref model) => &model.ietf_primary_language_subtag,
TtsModelForListMigrationWrapper::ModelWeight(ref model) => &model.ietf_primary_language_subtag,
}
}
pub fn creator_user_token(&self) -> &str {
match self {
TtsModelForList::LegacyTts(ref model) => &model.creator_user_token,
TtsModelForList::ModelWeight(ref model) => model.creator_user_token.as_str(),
TtsModelForListMigrationWrapper::LegacyTts(ref model) => &model.creator_user_token,
TtsModelForListMigrationWrapper::ModelWeight(ref model) => model.creator_user_token.as_str(),
}
}
pub fn creator_username(&self) -> &str {
match self {
TtsModelForList::LegacyTts(ref model) => &model.creator_username,
TtsModelForList::ModelWeight(ref model) => &model.creator_username,
TtsModelForListMigrationWrapper::LegacyTts(ref model) => &model.creator_username,
TtsModelForListMigrationWrapper::ModelWeight(ref model) => &model.creator_username,
}
}
pub fn creator_display_name(&self) -> &str {
match self {
TtsModelForList::LegacyTts(ref model) => &model.creator_display_name,
TtsModelForList::ModelWeight(ref model) => &model.creator_display_name,
TtsModelForListMigrationWrapper::LegacyTts(ref model) => &model.creator_display_name,
TtsModelForListMigrationWrapper::ModelWeight(ref model) => &model.creator_display_name,
}
}
pub fn creator_gravatar_hash(&self) -> &str {
match self {
TtsModelForList::LegacyTts(ref model) => &model.creator_gravatar_hash,
TtsModelForList::ModelWeight(ref model) => &model.creator_gravatar_hash,
TtsModelForListMigrationWrapper::LegacyTts(ref model) => &model.creator_gravatar_hash,
TtsModelForListMigrationWrapper::ModelWeight(ref model) => &model.creator_gravatar_hash,
}
}
pub fn creator_set_visibility(&self) -> Visibility{
match self {
TtsModelForList::LegacyTts(ref model) => model.creator_set_visibility,
TtsModelForList::ModelWeight(ref model) => model.creator_set_visibility,
TtsModelForListMigrationWrapper::LegacyTts(ref model) => model.creator_set_visibility,
TtsModelForListMigrationWrapper::ModelWeight(ref model) => model.creator_set_visibility,
}
}
pub fn created_at(&self) -> &DateTime<Utc> {
match self {
TtsModelForList::LegacyTts(ref model) => &model.created_at,
TtsModelForList::ModelWeight(ref model) => &model.created_at,
TtsModelForListMigrationWrapper::LegacyTts(ref model) => &model.created_at,
TtsModelForListMigrationWrapper::ModelWeight(ref model) => &model.created_at,
}
}
pub fn updated_at(&self) -> &DateTime<Utc> {
match self {
TtsModelForList::LegacyTts(ref model) => &model.updated_at,
TtsModelForList::ModelWeight(ref model) => &model.updated_at,
TtsModelForListMigrationWrapper::LegacyTts(ref model) => &model.updated_at,
TtsModelForListMigrationWrapper::ModelWeight(ref model) => &model.updated_at,
}
}
// Not supported in the new table
pub fn is_front_page_featured(&self) -> bool {
match self {
TtsModelForList::LegacyTts(ref model) => model.is_front_page_featured,
TtsModelForList::ModelWeight(ref _model) => false,
TtsModelForListMigrationWrapper::LegacyTts(ref model) => model.is_front_page_featured,
TtsModelForListMigrationWrapper::ModelWeight(ref _model) => false,
}
}
// Not supported in the new table
pub fn user_ratings_positive_count(&self) -> u32 {
match self {
TtsModelForList::LegacyTts(ref model) => model.user_ratings_positive_count,
TtsModelForList::ModelWeight(ref _model) => 0,
TtsModelForListMigrationWrapper::LegacyTts(ref model) => model.user_ratings_positive_count,
TtsModelForListMigrationWrapper::ModelWeight(ref _model) => 0,
}
}
// Not supported in the new table
pub fn user_ratings_negative_count(&self) -> u32 {
match self {
TtsModelForList::LegacyTts(ref model) => model.user_ratings_negative_count,
TtsModelForList::ModelWeight(ref _model) => 0,
TtsModelForListMigrationWrapper::LegacyTts(ref model) => model.user_ratings_negative_count,
TtsModelForListMigrationWrapper::ModelWeight(ref _model) => 0,
}
}
// Not supported in the new table
pub fn user_ratings_total_count(&self) -> u32 {
match self {
TtsModelForList::LegacyTts(ref model) => model.user_ratings_total_count,
TtsModelForList::ModelWeight(ref _model) => 0,
TtsModelForListMigrationWrapper::LegacyTts(ref model) => model.user_ratings_total_count,
TtsModelForListMigrationWrapper::ModelWeight(ref _model) => 0,
}
}
}
@@ -6,7 +6,7 @@ use log::{info, warn};
use enums::by_table::generic_inference_jobs::inference_category::InferenceCategory;
use enums::by_table::tts_models::tts_model_type::TtsModelType;
use filesys::file_exists::file_exists;
use migration::text_to_speech::get_tts_model_for_run_inference_migration::{get_tts_model_for_run_inference_migration, TtsModelForRunInferenceMigration};
use migration::text_to_speech::get_tts_model_for_run_inference_migration::{get_tts_model_for_run_inference_migration, TtsModelForRunInferenceMigrationWrapper};
use migration::voice_conversion::query_vc_model_for_migration::{query_vc_model_for_migration, VcModel, VcModelError, VcModelType};
use mysql_queries::queries::generic_inference::job::list_available_generic_inference_jobs::AvailableInferenceJob;
use mysql_queries::queries::tts::tts_models::get_tts_model_for_inference_improved::{get_tts_model_for_inference_improved, TtsModelForInferenceError, TtsModelForInferenceRecord};
@@ -28,7 +28,7 @@ pub struct DependencyStatus {
pub enum MaybeInferenceModel {
None,
TtsModel(TtsModelForRunInferenceMigration),
TtsModel(TtsModelForRunInferenceMigrationWrapper),
VcModel(VcModel)
}
@@ -11,7 +11,7 @@ use errors::AnyhowResult;
use filesys::check_file_exists::check_file_exists;
use filesys::safe_delete_temp_directory::safe_delete_temp_directory;
use filesys::safe_delete_temp_file::safe_delete_temp_file;
use migration::text_to_speech::get_tts_model_for_run_inference_migration::TtsModelForRunInferenceMigration;
use migration::text_to_speech::get_tts_model_for_run_inference_migration::TtsModelForRunInferenceMigrationWrapper;
use mysql_queries::column_types::vocoder_type::VocoderType;
use mysql_queries::queries::generic_inference::job::list_available_generic_inference_jobs::AvailableInferenceJob;
use tts_common::clean_symbols::clean_symbols;
@@ -36,7 +36,7 @@ const TEST_REQUEST_TEXT: &str = "This is a test request.";
pub struct ProcessJobArgs<'a> {
pub job_dependencies: &'a JobDependencies,
pub job: &'a AvailableInferenceJob,
pub tts_model: &'a TtsModelForRunInferenceMigration,
pub tts_model: &'a TtsModelForRunInferenceMigrationWrapper,
pub raw_inference_text: &'a str,
}
@@ -13,7 +13,7 @@ use filesys::check_file_exists::check_file_exists;
use filesys::safe_delete_temp_directory::safe_delete_temp_directory;
use filesys::safe_delete_temp_file::safe_delete_temp_file;
use hashing::sha256::sha256_hash_string::sha256_hash_string;
use migration::text_to_speech::get_tts_model_for_run_inference_migration::TtsModelForRunInferenceMigration;
use migration::text_to_speech::get_tts_model_for_run_inference_migration::TtsModelForRunInferenceMigrationWrapper;
use mysql_queries::column_types::vocoder_type::VocoderType;
use mysql_queries::queries::generic_inference::job::list_available_generic_inference_jobs::AvailableInferenceJob;
use mysql_queries::queries::tts::tts_results::insert_tts_result::{insert_tts_result, JobType};
@@ -32,7 +32,7 @@ const TEST_REQUEST_TEXT: &str = "This is a test request.";
pub struct VitsProcessJobArgs<'a> {
pub job_dependencies: &'a JobDependencies,
pub job: &'a AvailableInferenceJob,
pub tts_model: &'a TtsModelForRunInferenceMigration,
pub tts_model: &'a TtsModelForRunInferenceMigrationWrapper,
pub raw_inference_text: &'a str,
}
@@ -18,7 +18,7 @@ use jobs_common::job_stats::JobStats;
use jobs_common::semi_persistent_cache_dir::SemiPersistentCacheDir;
use memory_caching::multi_item_ttl_cache::MultiItemTtlCache;
use memory_caching::ttl_key_counter::TtlKeyCounter;
use migration::text_to_speech::get_tts_model_for_run_inference_migration::TtsModelForRunInferenceMigration;
use migration::text_to_speech::get_tts_model_for_run_inference_migration::TtsModelForRunInferenceMigrationWrapper;
use migration::voice_conversion::query_vc_model_for_migration::VcModel;
use mysql_queries::common_inputs::container_environment_arg::ContainerEnvironmentArg;
use mysql_queries::mediators::firehose_publisher::FirehosePublisher;
@@ -163,7 +163,7 @@ pub struct FileSystemDetails {
// TODO: Move into the appropriate job-specific dependencies object.
pub struct JobCaches {
pub tts_model_record_cache: MultiItemTtlCache<String, TtsModelForRunInferenceMigration>,
pub tts_model_record_cache: MultiItemTtlCache<String, TtsModelForRunInferenceMigrationWrapper>,
pub vc_model_record_cache: MultiItemTtlCache<String, VcModel>,
/// Skip processing models if they're not on the filesystem.
@@ -20,7 +20,7 @@ use enums::common::visibility::Visibility;
use http_server_common::request::get_request_api_token::get_request_api_token;
use http_server_common::request::get_request_header_optional::get_request_header_optional;
use http_server_common::request::get_request_ip::get_request_ip;
use migration::text_to_speech::get_tts_model_for_enqueue_inference_migration::TtsModelForEnqueueInferenceMigration;
use migration::text_to_speech::get_tts_model_for_enqueue_inference_migration::TtsModelForEnqueueInferenceMigrationWrapper;
use mysql_queries::payloads::generic_inference_args::generic_inference_args::{GenericInferenceArgs, InferenceCategoryAbbreviated};
use mysql_queries::queries::generic_inference::web::insert_generic_inference_job::{insert_generic_inference_job, InsertGenericInferenceArgs};
use mysql_queries::queries::tts::tts_inference_jobs::insert_tts_inference_job::TtsInferenceJobInsertBuilder;
@@ -553,7 +553,7 @@ pub fn validate_inference_text(text: &str, plan: &Plan) -> Result<(), String> {
/// This is designed to fail closed (read: actually open!) rather than hit resources.
async fn check_if_authorized_to_use_model(
maybe_user_session: Option<&UserSessionExtended>,
tts_model: &TtsModelForEnqueueInferenceMigration,
tts_model: &TtsModelForEnqueueInferenceMigrationWrapper,
) -> bool {
match tts_model.creator_set_visibility() {
@@ -3,7 +3,7 @@ use sqlx::MySql;
use sqlx::pool::PoolConnection;
use errors::AnyhowResult;
use migration::text_to_speech::get_tts_model_for_enqueue_inference_migration::{get_tts_model_for_enqueue_inference_migration, TtsModelForEnqueueInferenceMigration};
use migration::text_to_speech::get_tts_model_for_enqueue_inference_migration::{get_tts_model_for_enqueue_inference_migration, TtsModelForEnqueueInferenceMigrationWrapper};
use redis_caching::redis_ttl_cache::RedisTtlCache;
use redis_common::redis_cache_keys::RedisCacheKeys;
@@ -14,7 +14,7 @@ pub async fn get_tts_model_with_caching(
redis_ttl_cache: &RedisTtlCache,
mysql_connection: &mut PoolConnection<MySql>,
use_weights_table: bool,
) -> AnyhowResult<Option<TtsModelForEnqueueInferenceMigration>> {
) -> AnyhowResult<Option<TtsModelForEnqueueInferenceMigrationWrapper>> {
// NB: Copy due to move. Not a cloned ref due to clippy lint
let model_token2 = model_token.to_string();