mirror of
https://github.com/SinTan1729/chhoto-url.git
synced 2025-12-05 21:10:23 -08:00
chg: Retry once for all generated links
Would improve experience for large databases.
This commit is contained in:
@@ -154,6 +154,8 @@ If you do choose to use a short UID despite anticipating collisions, it's recomm
|
|||||||
In the event of a collision, this variable will result in a single retry attempt using a UID four digits longer than
|
In the event of a collision, this variable will result in a single retry attempt using a UID four digits longer than
|
||||||
`slug_length`. It has no effect for adjective-name slugs.
|
`slug_length`. It has no effect for adjective-name slugs.
|
||||||
|
|
||||||
|
_Note: If not set, one retry will be attempted, just like adjective-name slugs. But it would use the same slug length._
|
||||||
|
|
||||||
### `listen_address`
|
### `listen_address`
|
||||||
|
|
||||||
The address Chhoto URL will bind to. Defaults to `0.0.0.0`.
|
The address Chhoto URL will bind to. Defaults to `0.0.0.0`.
|
||||||
|
|||||||
@@ -94,15 +94,20 @@ pub fn add_link(
|
|||||||
chunks.expiry_delay = chunks.expiry_delay.min(157784760);
|
chunks.expiry_delay = chunks.expiry_delay.min(157784760);
|
||||||
chunks.expiry_delay = chunks.expiry_delay.max(0);
|
chunks.expiry_delay = chunks.expiry_delay.max(0);
|
||||||
|
|
||||||
if is_link_valid(chunks.shortlink.as_str(), allow_capital_letters) {
|
if !shortlink_provided || is_link_valid(chunks.shortlink.as_str(), allow_capital_letters) {
|
||||||
match database::add_link(&chunks.shortlink, &chunks.longlink, chunks.expiry_delay, db) {
|
match database::add_link(&chunks.shortlink, &chunks.longlink, chunks.expiry_delay, db) {
|
||||||
Ok(expiry_time) => Ok((chunks.shortlink, expiry_time)),
|
Ok(expiry_time) => Ok((chunks.shortlink, expiry_time)),
|
||||||
Err(ClientError { reason }) => {
|
Err(ClientError { reason }) => {
|
||||||
if shortlink_provided {
|
if shortlink_provided {
|
||||||
Err(ClientError { reason })
|
Err(ClientError { reason })
|
||||||
} else if config.slug_style == "UID" && config.try_longer_slug {
|
} else {
|
||||||
// Optionally, retry with a longer slug length
|
// Optionally, retry with a longer slug length
|
||||||
chunks.shortlink = gen_link(style, len + 4, allow_capital_letters);
|
let retry_len = if config.slug_style == "UID" && config.try_longer_slug {
|
||||||
|
len + 4
|
||||||
|
} else {
|
||||||
|
len
|
||||||
|
};
|
||||||
|
chunks.shortlink = gen_link(style, retry_len, allow_capital_letters);
|
||||||
match database::add_link(
|
match database::add_link(
|
||||||
&chunks.shortlink,
|
&chunks.shortlink,
|
||||||
&chunks.longlink,
|
&chunks.longlink,
|
||||||
@@ -110,11 +115,11 @@ pub fn add_link(
|
|||||||
db,
|
db,
|
||||||
) {
|
) {
|
||||||
Ok(expiry_time) => Ok((chunks.shortlink, expiry_time)),
|
Ok(expiry_time) => Ok((chunks.shortlink, expiry_time)),
|
||||||
Err(_) => Err(ServerError),
|
Err(_) => {
|
||||||
|
error!("Something went wrong while adding a generated link.");
|
||||||
|
Err(ServerError)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
error!("Something went wrong while adding a link: {reason}");
|
|
||||||
Err(ServerError)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(ServerError) => Err(ServerError),
|
Err(ServerError) => Err(ServerError),
|
||||||
|
|||||||
Reference in New Issue
Block a user