Rename new_uuid function to generate_ulid

This commit is contained in:
silverpill 2023-02-12 22:04:31 +00:00
parent 80b9032cbc
commit bc3184cf77
20 changed files with 52 additions and 46 deletions

View file

@ -158,8 +158,10 @@ pub fn parse_extra_field(
#[cfg(test)]
mod tests {
use crate::utils::caip2::ChainId;
use crate::utils::id::new_uuid;
use crate::utils::{
caip2::ChainId,
id::generate_ulid,
};
use super::*;
const INSTANCE_URL: &str = "https://example.com";
@ -181,7 +183,7 @@ mod tests {
#[test]
fn test_payment_option() {
let user_id = new_uuid();
let user_id = generate_ulid();
let payment_option =
PaymentOption::ethereum_subscription(ChainId::ethereum_mainnet());
let subscription_page_url =

View file

@ -10,7 +10,7 @@ use crate::activitypub::{
use crate::config::Instance;
use crate::models::profiles::types::DbActorProfile;
use crate::models::users::types::User;
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
#[derive(Serialize)]
struct AcceptFollow {
@ -34,7 +34,7 @@ fn build_accept_follow(
follow_activity_id: &str,
) -> AcceptFollow {
// Accept(Follow) is idempotent so its ID can be random
let activity_id = local_object_id(instance_url, &new_uuid());
let activity_id = local_object_id(instance_url, &generate_ulid());
let actor_id = local_actor_id(instance_url, &actor_profile.username);
AcceptFollow {
context: build_default_context(),

View file

@ -9,7 +9,7 @@ use crate::activitypub::{
};
use crate::config::Instance;
use crate::models::users::types::User;
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
#[derive(Serialize)]
struct AddOrRemovePerson {
@ -35,7 +35,7 @@ fn build_update_collection(
remove: bool,
) -> AddOrRemovePerson {
let actor_id = local_actor_id(instance_url, sender_username);
let activity_id = local_object_id(instance_url, &new_uuid());
let activity_id = local_object_id(instance_url, &generate_ulid());
let activity_type = if remove { REMOVE } else { ADD };
let collection_id = collection.of(&actor_id);
AddOrRemovePerson {

View file

@ -68,7 +68,7 @@ pub fn prepare_follow(
#[cfg(test)]
mod tests {
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";
@ -79,7 +79,7 @@ mod tests {
username: "follower".to_string(),
..Default::default()
};
let follow_request_id = new_uuid();
let follow_request_id = generate_ulid();
let target_actor_id = "https://test.remote/actor/test";
let activity = build_follow(
INSTANCE_URL,

View file

@ -110,7 +110,7 @@ pub async fn prepare_like(
#[cfg(test)]
mod tests {
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";
@ -120,7 +120,7 @@ mod tests {
let author = DbActorProfile::default();
let post_id = "https://example.com/objects/123";
let post_author_id = "https://example.com/users/test";
let reaction_id = new_uuid();
let reaction_id = generate_ulid();
let activity = build_like(
INSTANCE_URL,
&author,

View file

@ -10,7 +10,7 @@ use crate::activitypub::{
};
use crate::config::Instance;
use crate::models::users::types::User;
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
#[derive(Serialize)]
pub struct MovePerson {
@ -36,7 +36,7 @@ pub fn build_move_person(
maybe_internal_activity_id: Option<&Uuid>,
) -> MovePerson {
let internal_activity_id = maybe_internal_activity_id.copied()
.unwrap_or(new_uuid());
.unwrap_or(generate_ulid());
let activity_id = local_object_id(instance_url, &internal_activity_id);
let actor_id = local_actor_id(instance_url, &sender.profile.username);
MovePerson {
@ -78,7 +78,7 @@ pub fn prepare_move_person(
#[cfg(test)]
mod tests {
use crate::models::profiles::types::DbActorProfile;
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";
@ -97,7 +97,7 @@ mod tests {
"https://server1.org/users/1".to_string(),
"https://server2.org/users/2".to_string(),
];
let internal_activity_id = new_uuid();
let internal_activity_id = generate_ulid();
let activity = build_move_person(
INSTANCE_URL,
&sender,

View file

@ -88,7 +88,7 @@ pub async fn prepare_undo_announce(
#[cfg(test)]
mod tests {
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";
@ -97,7 +97,7 @@ mod tests {
fn test_build_undo_announce() {
let announcer = DbActorProfile::default();
let post_author_id = "https://example.com/users/test";
let repost_id = new_uuid();
let repost_id = generate_ulid();
let activity = build_undo_announce(
INSTANCE_URL,
&announcer,

View file

@ -85,7 +85,7 @@ pub fn prepare_undo_follow(
#[cfg(test)]
mod tests {
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";
@ -97,7 +97,7 @@ mod tests {
..Default::default()
};
let target_actor_id = "https://test.remote/users/123";
let follow_request_id = new_uuid();
let follow_request_id = generate_ulid();
let activity = build_undo_follow(
INSTANCE_URL,
&actor_profile,

View file

@ -87,7 +87,7 @@ pub async fn prepare_undo_like(
#[cfg(test)]
mod tests {
use crate::activitypub::constants::AP_PUBLIC;
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";
@ -96,7 +96,7 @@ mod tests {
fn test_build_undo_like() {
let author = DbActorProfile::default();
let post_author_id = "https://example.com/users/test";
let reaction_id = new_uuid();
let reaction_id = generate_ulid();
let activity = build_undo_like(
INSTANCE_URL,
&author,

View file

@ -13,7 +13,7 @@ use crate::config::Instance;
use crate::database::{DatabaseClient, DatabaseError, DatabaseTypeError};
use crate::models::relationships::queries::get_followers;
use crate::models::users::types::User;
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
#[derive(Serialize)]
pub struct UpdatePerson {
@ -38,7 +38,7 @@ pub fn build_update_person(
let actor = get_local_actor(user, instance_url)?;
// Update(Person) is idempotent so its ID can be random
let internal_activity_id =
maybe_internal_activity_id.unwrap_or(new_uuid());
maybe_internal_activity_id.unwrap_or(generate_ulid());
let activity_id = local_object_id(instance_url, &internal_activity_id);
let activity = UpdatePerson {
context: build_default_context(),
@ -111,7 +111,7 @@ mod tests {
},
..Default::default()
};
let internal_id = new_uuid();
let internal_id = generate_ulid();
let activity = build_update_person(
INSTANCE_URL,
&user,

View file

@ -116,7 +116,7 @@ pub fn parse_local_object_id(
#[cfg(test)]
mod tests {
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
use super::*;
const INSTANCE_URL: &str = "https://example.org";
@ -159,7 +159,7 @@ mod tests {
#[test]
fn test_parse_local_object_id() {
let expected_uuid = new_uuid();
let expected_uuid = generate_ulid();
let object_id = format!(
"https://example.org/objects/{}",
expected_uuid,

View file

@ -77,7 +77,7 @@ use crate::utils::{
serialize_private_key,
},
currencies::Currency,
id::new_uuid,
id::generate_ulid,
passwords::hash_password,
};
use super::helpers::{follow_or_create_request, get_relationship};
@ -244,7 +244,7 @@ async fn get_unsigned_update(
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
let internal_activity_id = new_uuid();
let internal_activity_id = generate_ulid();
let activity = build_update_person(
&config.instance_url(),
&current_user,

View file

@ -7,7 +7,7 @@ use crate::models::cleanup::{
find_orphaned_ipfs_objects,
DeletionQueue,
};
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
use super::types::DbMediaAttachment;
pub async fn create_attachment(
@ -17,7 +17,7 @@ pub async fn create_attachment(
file_size: usize,
media_type: Option<String>,
) -> Result<DbMediaAttachment, DatabaseError> {
let attachment_id = new_uuid();
let attachment_id = generate_ulid();
let file_size: i32 = file_size.try_into()
.expect("value should be within bounds");
let inserted_row = db_client.query_one(

View file

@ -10,7 +10,7 @@ use crate::models::{
cleanup::{find_orphaned_files, DeletionQueue},
instances::queries::create_instance,
};
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
use super::types::{DbEmoji, EmojiImage};
pub async fn create_emoji(
@ -21,7 +21,7 @@ pub async fn create_emoji(
object_id: Option<&str>,
updated_at: &DateTime<Utc>,
) -> Result<DbEmoji, DatabaseError> {
let emoji_id = new_uuid();
let emoji_id = generate_ulid();
if let Some(hostname) = hostname {
create_instance(db_client, hostname).await?;
};

View file

@ -5,8 +5,10 @@ use crate::database::{
DatabaseClient,
DatabaseError,
};
use crate::utils::caip2::ChainId;
use crate::utils::id::new_uuid;
use crate::utils::{
caip2::ChainId,
id::generate_ulid,
};
use super::types::{DbInvoice, InvoiceStatus};
pub async fn create_invoice(
@ -17,7 +19,7 @@ pub async fn create_invoice(
payment_address: &str,
amount: i64,
) -> Result<DbInvoice, DatabaseError> {
let invoice_id = new_uuid();
let invoice_id = generate_ulid();
let row = db_client.query_one(
"
INSERT INTO invoice (

View file

@ -23,7 +23,7 @@ use crate::models::notifications::queries::{
use crate::models::profiles::queries::update_post_count;
use crate::models::profiles::types::DbActorProfile;
use crate::models::relationships::types::RelationshipType;
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
use super::types::{
DbPost,
Post,
@ -166,7 +166,7 @@ pub async fn create_post(
post_data: PostCreateData,
) -> Result<Post, DatabaseError> {
let transaction = db_client.transaction().await?;
let post_id = new_uuid();
let post_id = generate_ulid();
// Replying to reposts is not allowed
// Reposting of other reposts or non-public posts is not allowed
let insert_statement = format!(

View file

@ -15,8 +15,10 @@ use crate::models::cleanup::{
};
use crate::models::instances::queries::create_instance;
use crate::models::relationships::types::RelationshipType;
use crate::utils::currencies::Currency;
use crate::utils::id::new_uuid;
use crate::utils::{
currencies::Currency,
id::generate_ulid,
};
use super::types::{
DbActorProfile,
ExtraFields,
@ -31,7 +33,7 @@ pub async fn create_profile(
db_client: &impl DatabaseClient,
profile_data: ProfileCreateData,
) -> Result<DbActorProfile, DatabaseError> {
let profile_id = new_uuid();
let profile_id = generate_ulid();
if let Some(ref hostname) = profile_data.hostname {
create_instance(db_client, hostname).await?;
};

View file

@ -10,7 +10,7 @@ use crate::models::posts::queries::{
update_reaction_count,
get_post_author,
};
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
use super::types::DbReaction;
pub async fn create_reaction(
@ -20,7 +20,7 @@ pub async fn create_reaction(
activity_id: Option<&String>,
) -> Result<DbReaction, DatabaseError> {
let transaction = db_client.transaction().await?;
let reaction_id = new_uuid();
let reaction_id = generate_ulid();
// Reactions to reposts are not allowed
let maybe_row = transaction.query_opt(
"

View file

@ -12,7 +12,7 @@ use crate::models::profiles::queries::{
update_subscriber_count,
};
use crate::models::profiles::types::DbActorProfile;
use crate::utils::id::new_uuid;
use crate::utils::id::generate_ulid;
use super::types::{
DbFollowRequest,
DbRelationship,
@ -142,7 +142,7 @@ pub async fn create_follow_request(
source_id: &Uuid,
target_id: &Uuid,
) -> Result<DbFollowRequest, DatabaseError> {
let request_id = new_uuid();
let request_id = generate_ulid();
let row = db_client.query_one(
"
INSERT INTO follow_request (
@ -169,7 +169,7 @@ pub async fn create_remote_follow_request_opt(
target_id: &Uuid,
activity_id: &str,
) -> Result<DbFollowRequest, DatabaseError> {
let request_id = new_uuid();
let request_id = generate_ulid();
let row = db_client.query_one(
"
INSERT INTO follow_request (

View file

@ -2,7 +2,7 @@ use ulid::Ulid;
use uuid::Uuid;
/// Produces new lexicographically sortable ID
pub fn new_uuid() -> Uuid {
pub fn generate_ulid() -> Uuid {
let ulid = Ulid::new();
Uuid::from(ulid)
}