mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-03 08:57:54 +00:00
Added more data for seeding
Added to test lists need to get list_weights_by_user tested
This commit is contained in:
1 parent
df3fc1bf51
commit
ddb35c5133
6 files changed
+516
-202
No files matched your search
@@ -10,10 +10,12 @@ use errors::AnyhowResult;
|
||||
use crate::cli_args::parse_cli_args;
|
||||
|
||||
use crate::seeding::model_weights::seed_weights;
|
||||
use crate::seeding::model_weights::seed_weights_for_user_token;
|
||||
use crate::seeding::users::seed_user_accounts;
|
||||
use crate::seeding::voice_conversion::seed_voice_conversion;
|
||||
use crate::seeding::zero_shot_tts::seed_zero_shot_tts;
|
||||
|
||||
|
||||
pub mod cli_args;
|
||||
pub mod seeding;
|
||||
|
||||
|
||||
@@ -7,13 +7,164 @@ use enums::by_table::model_weights::{
|
||||
weights_category::WeightsCategory,
|
||||
};
|
||||
use errors::{ anyhow, AnyhowResult };
|
||||
use mysql_queries::queries::users::user::get_user_token_by_username::get_user_token_by_username;
|
||||
|
||||
use crate::seeding::users::HANASHI_USERNAME;
|
||||
use mysql_queries::queries::model_weights::create_weight::{ create_weight, CreateModelWeightsArgs };
|
||||
use tokens::tokens::model_weights::ModelWeightToken;
|
||||
use enums::common::visibility::Visibility;
|
||||
|
||||
use mysql_queries::queries::users::user::get_user_token_by_username::get_user_token_by_username;
|
||||
|
||||
pub async fn seed_weights_for_user_token(
|
||||
mysql_pool: &Pool<MySql>,
|
||||
user_token: UserToken
|
||||
) -> AnyhowResult<()> {
|
||||
info!("Seeding weights...");
|
||||
|
||||
let model_weight_token1 = ModelWeightToken("11".to_string());
|
||||
let model_weight_token2 = ModelWeightToken("22".to_string());
|
||||
let model_weight_token3 = ModelWeightToken("33".to_string());
|
||||
let model_weight_token4 = ModelWeightToken("44".to_string());
|
||||
let model_weight_token5 = ModelWeightToken("55".to_string());
|
||||
|
||||
let model_weights_args = vec![
|
||||
CreateModelWeightsArgs {
|
||||
token: &model_weight_token1, // replace with actual ModelWeightToken
|
||||
weights_type: WeightsType::RvcV2, // replace with actual WeightsType
|
||||
weights_category: WeightsCategory::VoiceConversion, // replace with actual WeightsCategory
|
||||
title: "Title 1".to_string(),
|
||||
maybe_thumbnail_token: Some("Thumbnail 1".to_string()),
|
||||
description_markdown: "Description 1".to_string(),
|
||||
description_rendered_html: "<p>Description 1</p>".to_string(),
|
||||
creator_user_token: Some(&user_token), // replace with actual UserToken
|
||||
creator_ip_address: "192.168.1.1",
|
||||
creator_set_visibility: Visibility::Public,
|
||||
maybe_last_update_user_token: Some("Last Update User Token 1".to_string()),
|
||||
original_download_url: Some("http://example.com/download1".to_string()),
|
||||
original_filename: Some("filename1.txt".to_string()),
|
||||
file_size_bytes: 1024,
|
||||
file_checksum_sha2: "checksum1".to_string(),
|
||||
private_bucket_hash: "bucket_hash1".to_string(),
|
||||
maybe_private_bucket_prefix: Some("_fake".to_string()),
|
||||
maybe_private_bucket_extension: Some("rvc".to_string()),
|
||||
cached_user_ratings_total_count: 10,
|
||||
cached_user_ratings_positive_count: 9,
|
||||
cached_user_ratings_negative_count: 1,
|
||||
maybe_cached_user_ratings_ratio: Some(0.9),
|
||||
version: 1,
|
||||
mysql_pool: &mysql_pool, // replace with actual MySqlPool
|
||||
},
|
||||
CreateModelWeightsArgs {
|
||||
token: &model_weight_token2, // replace with actual ModelWeightToken
|
||||
weights_type: WeightsType::HifiganTacotron2, // replace with actual WeightsType
|
||||
weights_category: WeightsCategory::TextToSpeech, // replace with actual WeightsCategory
|
||||
title: "Title 2".to_string(),
|
||||
maybe_thumbnail_token: Some("Thumbnail 2".to_string()),
|
||||
description_markdown: "Description 2".to_string(),
|
||||
description_rendered_html: "<p>Description 2</p>".to_string(),
|
||||
creator_user_token: Some(&user_token), // replace with actual UserToken
|
||||
creator_ip_address: "292.268.2.2",
|
||||
creator_set_visibility: Visibility::Public,
|
||||
maybe_last_update_user_token: Some("Last Update User Token 2".to_string()),
|
||||
original_download_url: Some("http://example.com/download2".to_string()),
|
||||
original_filename: Some("filename2.txt".to_string()),
|
||||
file_size_bytes: 2024,
|
||||
file_checksum_sha2: "checksum2".to_string(),
|
||||
private_bucket_hash: "bucket_hash2".to_string(),
|
||||
maybe_private_bucket_prefix: Some("_fake".to_string()),
|
||||
maybe_private_bucket_extension: Some("tt2".to_string()),
|
||||
cached_user_ratings_total_count: 20,
|
||||
cached_user_ratings_positive_count: 9,
|
||||
cached_user_ratings_negative_count: 2,
|
||||
maybe_cached_user_ratings_ratio: Some(0.9),
|
||||
version: 2,
|
||||
mysql_pool: &mysql_pool, // replace with actual MySqlPool
|
||||
},
|
||||
CreateModelWeightsArgs {
|
||||
token: &model_weight_token3, // replace with actual ModelWeightToken
|
||||
weights_type: WeightsType::StableDiffusion15, // replace with actual WeightsType
|
||||
weights_category: WeightsCategory::ImageGeneration, // replace with actual WeightsCategory
|
||||
title: "Title 3".to_string(),
|
||||
maybe_thumbnail_token: Some("Thumbnail 3".to_string()),
|
||||
description_markdown: "Description 3".to_string(),
|
||||
description_rendered_html: "<p>Description 3</p>".to_string(),
|
||||
creator_user_token: Some(&user_token), // replace with actual UserToken
|
||||
creator_ip_address: "392.368.3.3",
|
||||
creator_set_visibility: Visibility::Public,
|
||||
maybe_last_update_user_token: Some("Last Update User Token 3".to_string()),
|
||||
original_download_url: Some("http://example.com/download3".to_string()),
|
||||
original_filename: Some("filename3.txt".to_string()),
|
||||
file_size_bytes: 3024,
|
||||
file_checksum_sha2: "checksum3".to_string(),
|
||||
private_bucket_hash: "bucket_hash3".to_string(),
|
||||
maybe_private_bucket_prefix: Some("_fake".to_string()),
|
||||
maybe_private_bucket_extension: Some("safetensors".to_string()),
|
||||
cached_user_ratings_total_count: 10,
|
||||
cached_user_ratings_positive_count: 9,
|
||||
cached_user_ratings_negative_count: 1,
|
||||
maybe_cached_user_ratings_ratio: Some(0.9),
|
||||
version: 1,
|
||||
mysql_pool: &mysql_pool, // replace with actual MySqlPool
|
||||
},
|
||||
CreateModelWeightsArgs {
|
||||
token: &model_weight_token4, // replace with actual ModelWeightToken
|
||||
weights_type: WeightsType::LoRA, // replace with actual WeightsType
|
||||
weights_category: WeightsCategory::ImageGeneration, // replace with actual WeightsCategory
|
||||
title: "Title 4".to_string(),
|
||||
maybe_thumbnail_token: Some("Thumbnail 4".to_string()),
|
||||
description_markdown: "Description 4".to_string(),
|
||||
description_rendered_html: "<p>Description 4</p>".to_string(),
|
||||
creator_user_token: Some(&user_token), // replace with actual UserToken
|
||||
creator_ip_address: "192.168.1.1",
|
||||
creator_set_visibility: Visibility::Public,
|
||||
maybe_last_update_user_token: Some("Last Update User Token 4".to_string()),
|
||||
original_download_url: Some("http://example.com/download1".to_string()),
|
||||
original_filename: Some("filename1.txt".to_string()),
|
||||
file_size_bytes: 1024,
|
||||
file_checksum_sha2: "checksum4".to_string(),
|
||||
private_bucket_hash: "bucket_hash4".to_string(),
|
||||
maybe_private_bucket_prefix: Some("_fake".to_string()),
|
||||
maybe_private_bucket_extension: Some("LoRA".to_string()),
|
||||
cached_user_ratings_total_count: 10,
|
||||
cached_user_ratings_positive_count: 9,
|
||||
cached_user_ratings_negative_count: 1,
|
||||
maybe_cached_user_ratings_ratio: Some(0.9),
|
||||
version: 2,
|
||||
mysql_pool: &mysql_pool, // replace with actual MySqlPool
|
||||
},
|
||||
CreateModelWeightsArgs {
|
||||
token: &model_weight_token5, // replace with actual ModelWeightToken
|
||||
weights_type: WeightsType::LoRA, // replace with actual WeightsType
|
||||
weights_category: WeightsCategory::ImageGeneration, // replace with actual WeightsCategory
|
||||
title: "Title 5".to_string(),
|
||||
maybe_thumbnail_token: Some("Thumbnail 4".to_string()),
|
||||
description_markdown: "Description 4".to_string(),
|
||||
description_rendered_html: "<p>Description 4</p>".to_string(),
|
||||
creator_user_token: Some(&user_token), // replace with actual UserToken
|
||||
creator_ip_address: "192.168.1.1",
|
||||
creator_set_visibility: Visibility::Public,
|
||||
maybe_last_update_user_token: Some("Last Update User Token 4".to_string()),
|
||||
original_download_url: Some("http://example.com/download1".to_string()),
|
||||
original_filename: Some("filename1.txt".to_string()),
|
||||
file_size_bytes: 1024,
|
||||
file_checksum_sha2: "checksum4".to_string(),
|
||||
private_bucket_hash: "bucket_hash4".to_string(),
|
||||
maybe_private_bucket_prefix: Some("_fake".to_string()),
|
||||
maybe_private_bucket_extension: Some("LoRA".to_string()),
|
||||
cached_user_ratings_total_count: 10,
|
||||
cached_user_ratings_positive_count: 9,
|
||||
cached_user_ratings_negative_count: 1,
|
||||
maybe_cached_user_ratings_ratio: Some(0.9),
|
||||
version: 2,
|
||||
mysql_pool: &mysql_pool, // replace with actual MySqlPool
|
||||
}
|
||||
];
|
||||
|
||||
for model_weights_arg in model_weights_args {
|
||||
create_weight(model_weights_arg).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub async fn seed_weights(mysql_pool: &Pool<MySql>) -> AnyhowResult<()> {
|
||||
info!("Seeding weights...");
|
||||
|
||||
@@ -25,7 +176,7 @@ pub async fn seed_weights(mysql_pool: &Pool<MySql>) -> AnyhowResult<()> {
|
||||
};
|
||||
|
||||
let model_weight_token1 = ModelWeightToken("1".to_string());
|
||||
let creator_token1 = UserToken("creatorToken!1".to_string());
|
||||
let creator_token1 = UserToken("creatorToken1".to_string());
|
||||
|
||||
let model_weight_token2 = ModelWeightToken("2".to_string());
|
||||
let creator_token2 = UserToken("creatorToken2".to_string());
|
||||
@@ -36,6 +187,9 @@ pub async fn seed_weights(mysql_pool: &Pool<MySql>) -> AnyhowResult<()> {
|
||||
let model_weight_token4 = ModelWeightToken("4".to_string());
|
||||
let creator_token4 = UserToken("creatorToken4".to_string());
|
||||
|
||||
let model_weight_token5 = ModelWeightToken("5".to_string());
|
||||
let creator_token5 = UserToken("creatorToken5".to_string());
|
||||
|
||||
let model_weights_args = vec![
|
||||
CreateModelWeightsArgs {
|
||||
token: &model_weight_token1, // replace with actual ModelWeightToken
|
||||
@@ -116,37 +270,66 @@ pub async fn seed_weights(mysql_pool: &Pool<MySql>) -> AnyhowResult<()> {
|
||||
mysql_pool: &mysql_pool, // replace with actual MySqlPool
|
||||
},
|
||||
CreateModelWeightsArgs {
|
||||
token: &model_weight_token4, // replace with actual ModelWeightToken
|
||||
weights_type: WeightsType::LoRA, // replace with actual WeightsType
|
||||
weights_category: WeightsCategory::ImageGeneration, // replace with actual WeightsCategory
|
||||
title: "Title 4".to_string(),
|
||||
maybe_thumbnail_token: Some("Thumbnail 4".to_string()),
|
||||
description_markdown: "Description 4".to_string(),
|
||||
description_rendered_html: "<p>Description 4</p>".to_string(),
|
||||
creator_user_token: Some(&creator_token4), // replace with actual UserToken
|
||||
creator_ip_address: "192.168.1.1",
|
||||
creator_set_visibility: Visibility::Public,
|
||||
maybe_last_update_user_token: Some("Last Update User Token 4".to_string()),
|
||||
original_download_url: Some("http://example.com/download1".to_string()),
|
||||
original_filename: Some("filename1.txt".to_string()),
|
||||
file_size_bytes: 1024,
|
||||
file_checksum_sha2: "checksum4".to_string(),
|
||||
private_bucket_hash: "bucket_hash4".to_string(),
|
||||
maybe_private_bucket_prefix: Some("_fake".to_string()),
|
||||
maybe_private_bucket_extension: Some("LoRA".to_string()),
|
||||
cached_user_ratings_total_count: 10,
|
||||
cached_user_ratings_positive_count: 9,
|
||||
cached_user_ratings_negative_count: 1,
|
||||
maybe_cached_user_ratings_ratio: Some(0.9),
|
||||
version: 2,
|
||||
mysql_pool: &mysql_pool, // replace with actual MySqlPool
|
||||
}
|
||||
token: &model_weight_token4, // replace with actual ModelWeightToken
|
||||
weights_type: WeightsType::LoRA, // replace with actual WeightsType
|
||||
weights_category: WeightsCategory::ImageGeneration, // replace with actual WeightsCategory
|
||||
title: "Title 4".to_string(),
|
||||
maybe_thumbnail_token: Some("Thumbnail 4".to_string()),
|
||||
description_markdown: "Description 4".to_string(),
|
||||
description_rendered_html: "<p>Description 4</p>".to_string(),
|
||||
creator_user_token: Some(&creator_token4), // replace with actual UserToken
|
||||
creator_ip_address: "192.168.1.1",
|
||||
creator_set_visibility: Visibility::Public,
|
||||
maybe_last_update_user_token: Some("Last Update User Token 4".to_string()),
|
||||
original_download_url: Some("http://example.com/download1".to_string()),
|
||||
original_filename: Some("filename1.txt".to_string()),
|
||||
file_size_bytes: 1024,
|
||||
file_checksum_sha2: "checksum4".to_string(),
|
||||
private_bucket_hash: "bucket_hash4".to_string(),
|
||||
maybe_private_bucket_prefix: Some("_fake".to_string()),
|
||||
maybe_private_bucket_extension: Some("LoRA".to_string()),
|
||||
cached_user_ratings_total_count: 10,
|
||||
cached_user_ratings_positive_count: 9,
|
||||
cached_user_ratings_negative_count: 1,
|
||||
maybe_cached_user_ratings_ratio: Some(0.9),
|
||||
version: 2,
|
||||
mysql_pool: &mysql_pool, // replace with actual MySqlPool
|
||||
},
|
||||
CreateModelWeightsArgs {
|
||||
token: &model_weight_token5, // replace with actual ModelWeightToken
|
||||
weights_type: WeightsType::LoRA, // replace with actual WeightsType
|
||||
weights_category: WeightsCategory::ImageGeneration, // replace with actual WeightsCategory
|
||||
title: "Title 5".to_string(),
|
||||
maybe_thumbnail_token: Some("Thumbnail 5".to_string()),
|
||||
description_markdown: "Description 5".to_string(),
|
||||
description_rendered_html: "<p>Description 5</p>".to_string(),
|
||||
creator_user_token: Some(&creator_token5), // replace with actual UserToken
|
||||
creator_ip_address: "192.168.1.1",
|
||||
creator_set_visibility: Visibility::Public,
|
||||
maybe_last_update_user_token: Some("Last Update User Token 5".to_string()),
|
||||
original_download_url: Some("http://example.com/download1".to_string()),
|
||||
original_filename: Some("filename1.txt".to_string()),
|
||||
file_size_bytes: 1025,
|
||||
file_checksum_sha2: "checksum5".to_string(),
|
||||
private_bucket_hash: "bucket_hash5".to_string(),
|
||||
maybe_private_bucket_prefix: Some("_fake".to_string()),
|
||||
maybe_private_bucket_extension: Some("LoRA".to_string()),
|
||||
cached_user_ratings_total_count: 10,
|
||||
cached_user_ratings_positive_count: 9,
|
||||
cached_user_ratings_negative_count: 1,
|
||||
maybe_cached_user_ratings_ratio: Some(0.9),
|
||||
version: 2,
|
||||
mysql_pool: &mysql_pool, // replace with actual MySqlPool
|
||||
}
|
||||
];
|
||||
|
||||
for model_weights_arg in model_weights_args {
|
||||
create_weight(model_weights_arg).await?;
|
||||
}
|
||||
|
||||
// adds this to HANASHI
|
||||
get_user_token_by_username(HANASHI_USERNAME, mysql_pool).await?;
|
||||
seed_weights_for_user_token(mysql_pool, user_token).await?;
|
||||
|
||||
Ok(())
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,35 @@
|
||||
use anyhow::anyhow;
|
||||
use chrono::{DateTime, Utc};
|
||||
use log::{info, warn};
|
||||
use sqlx::{MySql, MySqlPool};
|
||||
use chrono::{ DateTime, Utc };
|
||||
use log::{ info, warn };
|
||||
use sqlx::{ MySql, MySqlPool, query };
|
||||
use sqlx::pool::PoolConnection;
|
||||
|
||||
// let result = sqlx
|
||||
// ::query_as!(
|
||||
// RawWeightJoinUser,
|
||||
// r#"
|
||||
// SELECT
|
||||
// mw.token as `token: tokens::tokens::model_weights::ModelWeightsToken`,
|
||||
// mw.title,
|
||||
// users.token as `creator_user_token: tokens::tokens::users::UserToken`,
|
||||
// users.username as creator_username,
|
||||
// users.display_name as creator_display_name,
|
||||
// users.email_gravatar_hash as creator_email_gravatar_hash,
|
||||
// mw.creator_set_visibility as `creator_set_visibility: enums::common::visibility::Visibility`,
|
||||
// mw.created_at,
|
||||
// mw.updated_at
|
||||
// FROM model_weights as mw
|
||||
// JOIN users
|
||||
// ON users.token = mw.creator_user_token
|
||||
// WHERE
|
||||
// users.username = ?
|
||||
// AND mw.user_deleted_at IS NULL
|
||||
// AND mw.mod_deleted_at IS NULL
|
||||
// "#,
|
||||
// creator_username
|
||||
// )
|
||||
// .fetch_all(mysql_connection).await?
|
||||
|
||||
use enums::common::visibility::Visibility;
|
||||
use errors::AnyhowResult;
|
||||
use tokens::tokens::model_weights::ModelWeightToken;
|
||||
@@ -21,174 +47,19 @@ pub struct WeightsJoinUserRecord {
|
||||
pub weights_type: WeightsType,
|
||||
pub weights_category: WeightsCategory,
|
||||
pub maybe_thumbnail_token: Option<String>,
|
||||
|
||||
pub description_markdown: String,
|
||||
pub description_rendered_html: String,
|
||||
|
||||
pub creator_user_token: UserToken,
|
||||
pub creator_ip_address: String,
|
||||
pub creator_set_visibility: Visibility,
|
||||
pub maybe_last_update_user_token: Option<UserToken>,
|
||||
pub original_download_url: Option<String>,
|
||||
pub original_filename: Option<String>,
|
||||
pub file_size_bytes: i32,
|
||||
pub file_checksum_sha2: String,
|
||||
pub private_bucket_hash: String,
|
||||
pub maybe_private_bucket_prefix: Option<String>,
|
||||
pub maybe_private_bucket_extension: Option<String>,
|
||||
pub cached_user_ratings_negative_count: u32,
|
||||
pub cached_user_ratings_positive_count: u32,
|
||||
pub cached_user_ratings_total_count: u32,
|
||||
pub maybe_cached_user_ratings_ratio: Option<f32>,
|
||||
pub cached_user_ratings_last_updated_at: DateTime<Utc>,
|
||||
pub version: i32,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
pub user_deleted_at: Option<DateTime<Utc>>,
|
||||
pub mod_deleted_at: Option<DateTime<Utc>>
|
||||
}
|
||||
|
||||
pub async fn list_weights_by_username(
|
||||
mysql_pool: &MySqlPool,
|
||||
username: &str,
|
||||
can_see_deleted: bool,
|
||||
) -> AnyhowResult<Vec<WeightsJoinUserRecord>> {
|
||||
let mut connection = mysql_pool.acquire().await?;
|
||||
list_weights_by_username_with_connection(&mut connection, username, can_see_deleted).await
|
||||
}
|
||||
pub creator_username: String,
|
||||
pub creator_display_name: String,
|
||||
pub creator_email_gravatar_hash: String,
|
||||
|
||||
pub async fn list_weights_by_username_with_connection(
|
||||
mysql_connection: &mut PoolConnection<MySql>,
|
||||
creator_username: &str,
|
||||
can_see_deleted: bool,
|
||||
) -> AnyhowResult<Vec<WeightsJoinUserRecord>> {
|
||||
|
||||
let datasets =
|
||||
list_datasets_by_creator_username(mysql_connection, creator_username, can_see_deleted)
|
||||
.await;
|
||||
|
||||
let datasets : Vec<WeightsJoinUserRecord> = match datasets {
|
||||
Ok(datasets) => datasets,
|
||||
Err(err) => {
|
||||
match err {
|
||||
RowNotFound => {
|
||||
return Ok(Vec::new());
|
||||
},
|
||||
_ => {
|
||||
warn!("weights dataset list query error: {:?}", err);
|
||||
return Err(anyhow!("weights dataset list query error"));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ok(datasets.into_iter()
|
||||
.map(|dataset: WeightsJoinUserRecord| {
|
||||
WeightsJoinUserRecord {
|
||||
// weights_token: ModelWeightToken(dataset.token),
|
||||
// title: dataset.title,
|
||||
// creator_user_token: dataset.creator_user_token,
|
||||
// creator_username: dataset.creator_username,
|
||||
// creator_ip_address: dataset.creator_ip_address,
|
||||
// weights_type: dataset.weights_type,
|
||||
// weights_category: dataset.weights_category,
|
||||
// description_markdown: dataset.description_markdown,
|
||||
// description_rendered_html: dataset.description_rendered_html,
|
||||
// cached_user_ratings_negative_count: dataset.cached_user_ratings_negative_count,
|
||||
// cached_user_ratings_positive_count: dataset.cached_user_ratings_positive_count,
|
||||
// cached_user_ratings_total_count: dataset.cached_user_ratings_total_count,
|
||||
// maybe_cached_user_ratings_ratio: dataset.maybe_cached_user_ratings_ratio,
|
||||
// cached_user_ratings_total_count: dataset.cached_user_ratings_total_count,
|
||||
// created_at: dataset.created_at,
|
||||
// updated_at: dataset.updated_at,
|
||||
}
|
||||
})
|
||||
.filter(|dataset| {
|
||||
dataset.weights_token == creator_username || dataset.creator_set_visibility == Visibility::Public || can_see_deleted
|
||||
})
|
||||
.collect::<Vec<WeightsRecord>>())
|
||||
}
|
||||
|
||||
|
||||
async fn list_weights_by_creator_username(
|
||||
mysql_connection: &mut PoolConnection<MySql>,
|
||||
creator_username: &str,
|
||||
can_see_deleted: bool,
|
||||
) -> AnyhowResult<Vec<WeightsRecord>> {
|
||||
// TODO: There has to be a better way.
|
||||
// Sqlx doesn't like anything except string literals.
|
||||
let maybe_datasets = if !can_see_deleted {
|
||||
info!("listing datasets for user;");
|
||||
sqlx::query_as!(
|
||||
WeightsRecord,
|
||||
r#"
|
||||
SELECT
|
||||
zd.token as `token: tokens::tokens::zs_voice_datasets::ZsVoiceDatasetToken`,
|
||||
zd.title,
|
||||
zd.ietf_language_tag,
|
||||
zd.ietf_primary_language_subtag,
|
||||
users.token as `creator_user_token: tokens::tokens::users::UserToken`,
|
||||
users.username as creator_username,
|
||||
users.display_name as creator_display_name,
|
||||
users.email_gravatar_hash as creator_email_gravatar_hash,
|
||||
zd.creator_set_visibility as `creator_set_visibility: enums::common::visibility::Visibility`,
|
||||
zd.created_at,
|
||||
zd.updated_at
|
||||
FROM zs_voice_datasets as zd
|
||||
JOIN users
|
||||
ON users.token = zd.maybe_creator_user_token
|
||||
WHERE
|
||||
users.username = ?
|
||||
AND zd.user_deleted_at IS NULL
|
||||
AND zd.mod_deleted_at IS NULL
|
||||
"#,
|
||||
creator_username)
|
||||
.fetch_all(mysql_connection)
|
||||
.await?
|
||||
} else {
|
||||
info!("listing datasets for user");
|
||||
sqlx::query_as!(
|
||||
WeightsRecord
|
||||
,
|
||||
r#"
|
||||
SELECT
|
||||
zd.token as `token: tokens::tokens::zs_voice_datasets::ZsVoiceDatasetToken`,
|
||||
zd.title,
|
||||
zd.ietf_language_tag,
|
||||
zd.ietf_primary_language_subtag,
|
||||
users.token as `creator_user_token: tokens::tokens::users::UserToken`,
|
||||
users.username as creator_username,
|
||||
users.display_name as creator_display_name,
|
||||
users.email_gravatar_hash as creator_email_gravatar_hash,
|
||||
zd.creator_set_visibility as `creator_set_visibility: enums::common::visibility::Visibility`,
|
||||
zd.created_at,
|
||||
zd.updated_at
|
||||
FROM zs_voice_datasets as zd
|
||||
JOIN users
|
||||
ON users.token = zd.maybe_creator_user_token
|
||||
WHERE
|
||||
users.username = ?
|
||||
"#,
|
||||
creator_username)
|
||||
.fetch_all(mysql_connection)
|
||||
.await?
|
||||
};
|
||||
|
||||
Ok(maybe_datasets)
|
||||
}
|
||||
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct RawWeightJoinUser {
|
||||
pub token: ModelWeightToken,
|
||||
pub title: String,
|
||||
pub weights_type: WeightsType,
|
||||
pub weights_category: WeightsCategory,
|
||||
pub maybe_thumbnail_token: Option<String>,
|
||||
pub description_markdown: String,
|
||||
pub description_rendered_html: String,
|
||||
pub creator_user_token: UserToken,
|
||||
pub creator_ip_address: String,
|
||||
pub creator_set_visibility: Visibility,
|
||||
pub maybe_last_update_user_token: Option<UserToken>,
|
||||
pub original_download_url: Option<String>,
|
||||
pub original_filename: Option<String>,
|
||||
pub file_size_bytes: i32,
|
||||
@@ -208,12 +79,231 @@ pub struct RawWeightJoinUser {
|
||||
pub mod_deleted_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
assert_eq!("one", "two"); // This fails
|
||||
}
|
||||
|
||||
pub async fn list_weights_by_username(
|
||||
mysql_pool: &MySqlPool,
|
||||
username: &str,
|
||||
can_see_deleted: bool
|
||||
) -> AnyhowResult<Vec<WeightsJoinUserRecord>> {
|
||||
let mut connection = mysql_pool.acquire().await?;
|
||||
list_weights_by_username_with_connection(&mut connection, username, can_see_deleted).await
|
||||
}
|
||||
|
||||
pub async fn list_weights_by_username_with_connection(
|
||||
mysql_connection: &mut PoolConnection<MySql>,
|
||||
creator_username: &str,
|
||||
can_see_deleted: bool
|
||||
) -> AnyhowResult<Vec<WeightsJoinUserRecord>> {
|
||||
// query
|
||||
// let datasets = list_datasets_by_creator_username(
|
||||
// mysql_connection,
|
||||
// creator_username,
|
||||
// can_see_deleted
|
||||
// ).await;
|
||||
|
||||
// // map
|
||||
// let datasets: Vec<WeightsJoinUserRecord> = match datasets {
|
||||
// Ok(datasets) => datasets,
|
||||
// Err(err) => {
|
||||
// match err {
|
||||
// RowNotFound => {
|
||||
// return Ok(Vec::new());
|
||||
// }
|
||||
// _ => {
|
||||
// warn!("weights dataset list query error: {:?}", err);
|
||||
// return Err(anyhow!("weights dataset list query error"));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
// Ok(
|
||||
// datasets
|
||||
// .into_iter()
|
||||
// .map(|dataset: WeightsJoinUserRecord| {
|
||||
// WeightsJoinUserRecord {
|
||||
// token: dataset.token,
|
||||
// title: dataset.title,
|
||||
// weights_type: dataset.weights_type,
|
||||
// weights_category: dataset.weights_category,
|
||||
// maybe_thumbnail_token: dataset.maybe_thumbnail_token,
|
||||
// description_markdown: dataset.description_markdown,
|
||||
// description_rendered_html: dataset.description_rendered_html,
|
||||
|
||||
// creator_user_token: dataset.creator_user_token,
|
||||
// creator_ip_address: dataset.creator_ip_address,
|
||||
// creator_set_visibility: dataset.creator_set_visibility,
|
||||
|
||||
// maybe_last_update_user_token: dataset.maybe_last_update_user_token,
|
||||
// original_download_url: dataset.original_download_url,
|
||||
// original_filename: dataset.original_filename,
|
||||
// file_size_bytes: dataset.file_size_bytes,
|
||||
// file_checksum_sha2: dataset.file_checksum_sha2,
|
||||
// private_bucket_hash: dataset.private_bucket_hash,
|
||||
// maybe_private_bucket_prefix: dataset.maybe_private_bucket_prefix,
|
||||
// maybe_private_bucket_extension: dataset.maybe_private_bucket_extension,
|
||||
|
||||
// cached_user_ratings_negative_count: dataset.cached_user_ratings_negative_count,
|
||||
// cached_user_ratings_positive_count: dataset.cached_user_ratings_positive_count,
|
||||
// cached_user_ratings_total_count: dataset.cached_user_ratings_total_count,
|
||||
|
||||
// maybe_cached_user_ratings_ratio: dataset.maybe_cached_user_ratings_ratio,
|
||||
// cached_user_ratings_last_updated_at: dataset.cached_user_ratings_last_updated_at,
|
||||
// version: dataset.version,
|
||||
// created_at: dataset.created_at,
|
||||
// updated_at: dataset.updated_at,
|
||||
// user_deleted_at: dataset.user_deleted_at,
|
||||
// mod_deleted_at: dataset.mod_deleted_at,
|
||||
// }
|
||||
// })
|
||||
// .filter(|dataset| {
|
||||
// dataset.creator_user_token == creator_username ||
|
||||
// dataset.creator_set_visibility == Visibility::Public ||
|
||||
// can_see_deleted
|
||||
// })
|
||||
// .collect::<Vec<WeightsJoinUserRecord>>())
|
||||
let weights_records = Vec::<WeightsJoinUserRecord>::new();
|
||||
Ok(weights_records)
|
||||
|
||||
}
|
||||
|
||||
async fn list_datasets_by_creator_username(
|
||||
mysql_connection: &mut PoolConnection<MySql>,
|
||||
creator_username: &str,
|
||||
can_see_deleted: bool
|
||||
) -> AnyhowResult<Vec<WeightsJoinUserRecord>> {
|
||||
let model_weights: Vec<WeightsJoinUserRecord> = Vec::new();
|
||||
Ok(model_weights)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// CREATE TABLE model_weights (
|
||||
// id BIGINT(20) NOT NULL AUTO_INCREMENT,
|
||||
// token VARCHAR(32) NOT NULL,
|
||||
// weights_type VARCHAR(32) NOT NULL,
|
||||
// weights_category VARCHAR(32) NOT NULL,
|
||||
// title VARCHAR(255) NOT NULL,
|
||||
// maybe_thumbnail_token VARCHAR(32) DEFAULT NULL,
|
||||
// description_markdown TEXT NOT NULL,
|
||||
// description_rendered_html TEXT NOT NULL,
|
||||
// creator_user_token VARCHAR(32) NOT NULL,
|
||||
// creator_ip_address VARCHAR(40) NOT NULL,
|
||||
// creator_set_visibility ENUM(
|
||||
// 'public',
|
||||
// 'hidden',
|
||||
// 'private'
|
||||
// ) NOT NULL DEFAULT 'public',
|
||||
// maybe_last_update_user_token VARCHAR(32) DEFAULT NULL,
|
||||
// original_download_url VARCHAR(512) DEFAULT NULL,
|
||||
// original_filename VARCHAR(255) DEFAULT NULL,
|
||||
// file_size_bytes INT(10) NOT NULL DEFAULT 0,
|
||||
// file_checksum_sha2 CHAR(64) NOT NULL,
|
||||
// private_bucket_hash VARCHAR(32) NOT NULL,
|
||||
// maybe_private_bucket_prefix VARCHAR(16) DEFAULT NULL,
|
||||
// maybe_private_bucket_extension VARCHAR(16) DEFAULT NULL,
|
||||
// cached_user_ratings_total_count INT(10) UNSIGNED NOT NULL DEFAULT 0,
|
||||
// cached_user_ratings_positive_count INT(10) UNSIGNED NOT NULL DEFAULT 0,
|
||||
// cached_user_ratings_negative_count INT(10) UNSIGNED NOT NULL DEFAULT 0,
|
||||
// maybe_cached_user_ratings_ratio FLOAT,
|
||||
// cached_user_ratings_last_updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
// version INT NOT NULL DEFAULT 0,
|
||||
// created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
// updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
// user_deleted_at TIMESTAMP NULL,
|
||||
// mod_deleted_at TIMESTAMP NULL,
|
||||
// PRIMARY KEY (id),
|
||||
// UNIQUE KEY (token)
|
||||
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
|
||||
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct RawWeightJoinUser {
|
||||
pub token: ModelWeightToken,
|
||||
|
||||
pub weights_type: WeightsType,
|
||||
pub weights_category: WeightsCategory,
|
||||
|
||||
pub title: String,
|
||||
|
||||
pub maybe_thumbnail_token: Option<String>,
|
||||
|
||||
pub description_markdown: String,
|
||||
pub description_rendered_html: String,
|
||||
|
||||
pub creator_user_token: UserToken,
|
||||
pub creator_ip_address: String,
|
||||
pub creator_set_visibility: Visibility,
|
||||
|
||||
pub maybe_last_update_user_token: Option<UserToken>,
|
||||
|
||||
pub original_download_url: Option<String>,
|
||||
pub original_filename: Option<String>,
|
||||
|
||||
pub file_size_bytes: i32,
|
||||
pub file_checksum_sha2: String,
|
||||
|
||||
pub private_bucket_hash: String,
|
||||
|
||||
pub maybe_private_bucket_prefix: Option<String>,
|
||||
pub maybe_private_bucket_extension: Option<String>,
|
||||
|
||||
pub cached_user_ratings_total_count: u32,
|
||||
pub cached_user_ratings_positive_count: u32,
|
||||
pub cached_user_ratings_negative_count: u32,
|
||||
pub maybe_cached_user_ratings_ratio: Option<f32>,
|
||||
pub cached_user_ratings_last_updated_at: DateTime<Utc>,
|
||||
|
||||
pub version: i32,
|
||||
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
|
||||
pub user_deleted_at: Option<DateTime<Utc>>,
|
||||
pub mod_deleted_at: Option<DateTime<Utc>>,
|
||||
|
||||
pub username: String,
|
||||
pub display_name: String,
|
||||
pub email_gravatar_hash: String,
|
||||
}
|
||||
|
||||
|
||||
// SELECT
|
||||
// mw.token as `token: tokens::tokens::model_weights::ModelWeightsToken`,
|
||||
// mw.title,
|
||||
// mw.weights_type,
|
||||
// mw.weights_category,
|
||||
// mw.maybe_thumbnail_token,
|
||||
// mw.description_markdown,
|
||||
// mw.description_rendered_html,
|
||||
// users.token as `creator_user_token: tokens::tokens::users::UserToken`,
|
||||
// users.username as creator_username,
|
||||
// users.display_name as creator_display_name,
|
||||
// users.email_gravatar_hash as creator_email_gravatar_hash,
|
||||
// mw.creator_ip_address,
|
||||
// mw.creator_set_visibility as `creator_set_visibility: enums::common::visibility::Visibility`,
|
||||
// mw.maybe_last_update_user_token,
|
||||
// mw.original_download_url,
|
||||
// mw.original_filename,
|
||||
// mw.file_size_bytes,
|
||||
// mw.file_checksum_sha2,
|
||||
// mw.private_bucket_hash,
|
||||
// mw.maybe_private_bucket_prefix,
|
||||
// mw.maybe_private_bucket_extension,
|
||||
// mw.cached_user_ratings_negative_count,
|
||||
// mw.cached_user_ratings_positive_count,
|
||||
// mw.cached_user_ratings_total_count,
|
||||
// mw.maybe_cached_user_ratings_ratio,
|
||||
// mw.cached_user_ratings_last_updated_at,
|
||||
// mw.version,
|
||||
// mw.created_at,
|
||||
// mw.updated_at,
|
||||
// mw.user_deleted_at,
|
||||
// mw.mod_deleted_at
|
||||
// FROM model_weights as mw
|
||||
// JOIN users
|
||||
// ON users.token = mw.creator_user_token
|
||||
// WHERE
|
||||
// users.username = ?
|
||||
// AND mw.user_deleted_at IS NULL
|
||||
// AND mw.mod_deleted_at IS NULL
|
||||
@@ -2,6 +2,6 @@ pub mod create_weight;
|
||||
pub mod delete_weights;
|
||||
pub mod get_weight;
|
||||
pub mod update_weight;
|
||||
// pub mod list_weights_by_user;
|
||||
pub mod list_weights_by_user;
|
||||
// pub mod list_weights_query_builder;
|
||||
pub mod tests;
|
||||
@@ -0,0 +1,37 @@
|
||||
CREATE TABLE model_weights (
|
||||
id BIGINT(20) NOT NULL AUTO_INCREMENT,
|
||||
token VARCHAR(32) NOT NULL,
|
||||
weights_type VARCHAR(32) NOT NULL,
|
||||
weights_category VARCHAR(32) NOT NULL,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
maybe_thumbnail_token VARCHAR(32) DEFAULT NULL,
|
||||
description_markdown TEXT NOT NULL,
|
||||
description_rendered_html TEXT NOT NULL,
|
||||
creator_user_token VARCHAR(32) NOT NULL,
|
||||
creator_ip_address VARCHAR(40) NOT NULL,
|
||||
creator_set_visibility ENUM(
|
||||
'public',
|
||||
'hidden',
|
||||
'private'
|
||||
) NOT NULL DEFAULT 'public',
|
||||
maybe_last_update_user_token VARCHAR(32) DEFAULT NULL,
|
||||
original_download_url VARCHAR(512) DEFAULT NULL,
|
||||
original_filename VARCHAR(255) DEFAULT NULL,
|
||||
file_size_bytes INT(10) NOT NULL DEFAULT 0,
|
||||
file_checksum_sha2 CHAR(64) NOT NULL,
|
||||
private_bucket_hash VARCHAR(32) NOT NULL,
|
||||
maybe_private_bucket_prefix VARCHAR(16) DEFAULT NULL,
|
||||
maybe_private_bucket_extension VARCHAR(16) DEFAULT NULL,
|
||||
cached_user_ratings_total_count INT(10) UNSIGNED NOT NULL DEFAULT 0,
|
||||
cached_user_ratings_positive_count INT(10) UNSIGNED NOT NULL DEFAULT 0,
|
||||
cached_user_ratings_negative_count INT(10) UNSIGNED NOT NULL DEFAULT 0,
|
||||
maybe_cached_user_ratings_ratio FLOAT,
|
||||
cached_user_ratings_last_updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
version INT NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
user_deleted_at TIMESTAMP NULL,
|
||||
mod_deleted_at TIMESTAMP NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY (token)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
@@ -279,6 +279,8 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_all_weights_by_user() -> AnyhowResult<()> {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user