Make stats collection opt-out

This commit is contained in:
Matthew Esposito 2023-06-09 17:26:23 -04:00
parent 255307a4f7
commit 5f562876f4
No known key found for this signature in database
6 changed files with 42 additions and 12 deletions

View file

@ -20,10 +20,11 @@ use std::{
result::Result,
str::{from_utf8, Split},
string::ToString,
sync::atomic::Ordering::SeqCst,
};
use time::Duration;
use crate::{dbg_msg, instance_info::INSTANCE_INFO};
use crate::{config, dbg_msg, instance_info::INSTANCE_INFO};
type BoxResponse = Pin<Box<dyn Future<Output = Result<Response<Body>, String>> + Send>>;
@ -234,8 +235,11 @@ impl Server {
match router.recognize(&format!("/{}{}", req.method().as_str(), path)) {
// If a route was configured for this path
Ok(found) => {
// Add to total_requests count
INSTANCE_INFO.total_requests.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
if config::get_setting("LIBREDDIT_DISABLE_STATS_COLLECTION").is_none() {
// Add to total_requests count
INSTANCE_INFO.total_requests.fetch_add(1, SeqCst);
}
let mut parammed = req;
parammed.set_params(found.params().clone());