Skip to content

Conversation

dethos
Copy link
Contributor

@dethos dethos commented Aug 12, 2025

For the last couple of months I've been running a modified version of Redlib on my personal “instance.”
I essentially added a new option to the settings that make Redlib remove common tracking elements from the links posted to Reddit. A small privacy gain when we don't have browser extensions to do this job.

Since it is running smoothly, I think this could benefit all Redlib users. So here's the PR; feel free to dismiss or suggest improvements.

@dethos dethos changed the title Clean links - Remove superflus tracking elementos from urls Clean links - remove superfluous tracking elements from URLs Aug 12, 2025
Copy link
Member

@sigaloid sigaloid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! Thanks for the PR - a few comments.

}

// Remove tracking query params
static URL_CLEANER: Lazy<Mutex<UrlCleaner>> = Lazy::new(|| Mutex::new(UrlCleaner::from_embedded_rules().expect("Failed to initialize UrlCleaner")));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we use a mutex? clear_single_url_str doesn't take &mut str as a parameter, so we don't need mutual exclusion, we should be able to get away with something like an Arc - this also improves performance as we don't have unnecessary lock contention. A static is a good idea though - so we only construct the UrlCleaner once without constantly reparsing rules.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment on lines +1086 to +1097
pub fn clean_url(url: String) -> String {
let is_external_url = match Url::parse(url.as_str()) {
Ok(parsed_url) => parsed_url.domain().is_some(),
_ => false,
};
let mut cleaned_url = url.clone();
if is_external_url {
let cleaner = URL_CLEANER.lock().unwrap();
cleaned_url = cleaner.clear_single_url_str(cleaned_url.as_str()).expect("Unable to clean the URL.").as_ref().to_owned();
}
cleaned_url
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should handle the failed cases better - specifically (once you remove the mutex) the expect for the UrlCleaner::clear_single_url_str call should fallback to the input, instead of panicking. This shouldn't happen since the clearurls::Error enum is pretty small (and default embedded rules presumably exclude most of them); but a malformed URL is very likely.

Comment on lines -1657 to +1679
"ఴӅβØØҞÉဏႢձĬ༧ȒʯऌԔӵ୮༏",
"ਧՊΥÀÃǎƱГ۸ඣമĖฤ႙ʟาúໜϾௐɥঀĜໃહཞઠѫҲɂఙ࿔DzઉƲӟӻĻฅΜδ໖ԜǗဖငƦơ৶Ą௩ԹʛใЛʃශаΏ",
"ਧԩΥÀÃΊ౭൩ඔႠϼҭöҪƸռઇԾॐნɔາǒՍҰच௨ಖມŃЉŐདƦ๙ϩএఠȝഽйʮჯඒϰळՋ௮ສ৵ऎΦѧਹಧଟƙŃ३î༦ŌပղयƟแҜ།",
"ਧӐΥºÃΦĴгౡୡϤҚԷŽဎՐΧΣೡຽဒ೨ʛĽତ๘Ӓǹভµɾ൦ॴцৱ௬చΣҭжҭȱȾཊజĊȔ௸७ƘȂј۰ȥėǨԯၻíႽਈႴ۹ଆ",
"ਧҫടºÃǒɣυໃਣөŕǁజ८ௐɪDžઘႴ౨ඛႻຫǪၼդɍ৪Êѕ୶ʭѹŪҚຊೱѰງიŠСঌາඌĨğਜડ࿅ଠಲೱҋŇƞਭăʁझшȖǾཔ௧ந۞ສÚ",
"ਧҫടºÃǒɿဧϯljഔค๖۞ԆНȦ൨ĭ྅ҤƍตཧႯƅशञঊମਇȕමзқଽijჰଐՋບӎՓஶཕ૭ଛกήऋĜɀಱӔԩझԩîဓŒԬũլಙટщೞຝ৪༎",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should leave the old configs there, so that we can confirm backwards compatibility is preserved.

Comment on lines +675 to +676
#[revision(start = 1)]
pub clean_urls: String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review revision docs to handle this - specifically, you'll want to increment the upper level struct's revision to 2, set the start for clean_urls to 2, and read the docs on how you'll handle reverse compatibility (default to off).

Comment on lines -162 to +164
if subscriptions.is_some() {
let sub_list: Vec<String> = subscriptions.expect("Subscriptions").split('+').map(str::to_string).collect();
if let Some(subscriptions) = subscriptions {
let sub_list: Vec<String> = subscriptions.split('+').map(str::to_string).collect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave this unpatched (as well as :213-214) - I'd rather atomic PR's and fixed this in main - ignore the CI/CD checks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants