From e66eb1e6c3fce910f0a18ae888ecf56b50c59a30 Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Thu, 26 Sep 2024 00:52:39 +0530 Subject: [PATCH 1/3] Don't update reports on pages containing {{nobots}} --- dbreps2/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dbreps2/src/lib.rs b/dbreps2/src/lib.rs index 3dede14..32fd347 100644 --- a/dbreps2/src/lib.rs +++ b/dbreps2/src/lib.rs @@ -192,6 +192,9 @@ pub trait Report { return Ok(true); } } + if contains_nobot(old_text) { + return Ok(false); + } let re = Regex::new("(.*?)").unwrap(); let ts = match re.captures(old_text) { Some(cap) => cap[1].to_string(), @@ -450,6 +453,10 @@ pub fn y_m_d(input: &str) -> String { .unwrap_or_else(|_| input.to_string()) } +pub fn contains_nobot(text: &str) -> bool { + Regex::new("\\{\\{nobots}}").unwrap().is_match(text) +} + #[cfg(test)] mod tests { use super::*; @@ -515,4 +522,16 @@ mod tests { "This report is updated every day at 3:00 UTC." ); } + + #[test] + fn test_contains_nobot() { + assert_eq!( + contains_nobot("{{nobots}}. Some text here."), + true + ); + assert_eq!( + contains_nobot("Some text here"), + false + ); + } } From 4866cd944c0f2c212aace2f35ef1688bcc11d639 Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Thu, 26 Sep 2024 11:40:21 +0530 Subject: [PATCH 2/3] Don't update reports on pages containing {{database report}} --- dbreps2/src/lib.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/dbreps2/src/lib.rs b/dbreps2/src/lib.rs index 32fd347..b59cd2f 100644 --- a/dbreps2/src/lib.rs +++ b/dbreps2/src/lib.rs @@ -192,7 +192,7 @@ pub trait Report { return Ok(true); } } - if contains_nobot(old_text) { + if contains_database_report_template(old_text) { return Ok(false); } let re = Regex::new("(.*?)").unwrap(); @@ -453,8 +453,10 @@ pub fn y_m_d(input: &str) -> String { .unwrap_or_else(|_| input.to_string()) } -pub fn contains_nobot(text: &str) -> bool { - Regex::new("\\{\\{nobots}}").unwrap().is_match(text) +pub fn contains_database_report_template(text: &str) -> bool { + Regex::new("\\{\\{[Dd]atabase report\\s*\\|") + .unwrap() + .is_match(text) } #[cfg(test)] @@ -524,14 +526,18 @@ mod tests { } #[test] - fn test_contains_nobot() { + fn test_contains_database_report_template() { + assert_eq!(contains_database_report_template( + "Some text here. {{database report|sql=SELECT * FROM page LIMIT 10}}"), true); assert_eq!( - contains_nobot("{{nobots}}. Some text here."), + contains_database_report_template( + "Some text here. \ + {{database report\ + |sql=SELECT * FROM page LIMIT 10\ + }}" + ), true ); - assert_eq!( - contains_nobot("Some text here"), - false - ); + assert_eq!(contains_database_report_template("Some text here"), false); } } From 414748b4293d4e18f02afbb9cc65a77917ca8fce Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Sat, 28 Sep 2024 02:10:25 +0530 Subject: [PATCH 3/3] add comment --- dbreps2/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dbreps2/src/lib.rs b/dbreps2/src/lib.rs index b59cd2f..a065d25 100644 --- a/dbreps2/src/lib.rs +++ b/dbreps2/src/lib.rs @@ -192,6 +192,9 @@ pub trait Report { return Ok(true); } } + + // Pages with {{database report}} are maintained by SDZeroBot and contain the SQL queries + // directly. Skip updating the report if it has been migrated to use that template. if contains_database_report_template(old_text) { return Ok(false); }