refactor: address review — sort_by_key and optional comment timestamps

This commit is contained in:
2026-06-05 15:01:14 +02:00
parent 4980beec0a
commit a5896e046c
+3 -3
View File
@@ -42,7 +42,7 @@ struct Statistics {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct RawComment { struct RawComment {
comment: String, comment: String,
timestamp: u64, timestamp: Option<u64>,
} }
pub fn request_urls(number: &str) -> Vec<String> { pub fn request_urls(number: &str) -> Vec<String> {
@@ -96,13 +96,13 @@ pub fn parse(body: &str) -> Result<ParsedEntry, ParseError> {
.into_iter() .into_iter()
.filter(|raw| !raw.comment.trim().is_empty()) .filter(|raw| !raw.comment.trim().is_empty())
.map(|raw| ParsedComment { .map(|raw| ParsedComment {
timestamp: Some((raw.timestamp / 1000) as i64), timestamp: raw.timestamp.map(|millis| (millis / 1000) as i64),
title: None, title: None,
message: raw.comment, message: raw.comment,
}) })
.collect(); .collect();
comments.sort_by(|a, b| b.timestamp.cmp(&a.timestamp)); comments.sort_by_key(|comment| std::cmp::Reverse(comment.timestamp));
return Ok(ParsedEntry { return Ok(ParsedEntry {
messages: Vec::new(), messages: Vec::new(),