Skip to content

Commit 4c9bba3

Browse files
committed
fixup! perf: apply details/changes only on the relevant events
1 parent 300a3f6 commit 4c9bba3

4 files changed

Lines changed: 8 additions & 14 deletions

File tree

src/apply_changes.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn apply_change(
1616
if change.remove {
1717
match removed_events {
1818
RemovedEvents::Cancelled => event.status = EventStatus::Cancelled,
19-
RemovedEvents::Emoji => event.pretty_name.insert_str(0, "🚫 "),
19+
RemovedEvents::Emoji => event.name.insert_str(0, "🚫 "),
2020
RemovedEvents::Removed => {
2121
events.remove(i);
2222
return;
@@ -25,8 +25,8 @@ pub fn apply_change(
2525
}
2626

2727
if let Some(namesuffix) = &change.namesuffix {
28-
event.pretty_name += " ";
29-
event.pretty_name += namesuffix;
28+
event.name += " ";
29+
event.name += namesuffix;
3030
}
3131

3232
if let Some(room) = change.room {
@@ -51,7 +51,6 @@ fn generate_events() -> Vec<SoonToBeIcsEvent> {
5151
vec![
5252
SoonToBeIcsEvent {
5353
name: "BTI5-VSP/01".to_owned(),
54-
pretty_name: "BTI5-VSP/01".to_owned(),
5554
status: EventStatus::Confirmed,
5655
start_time: chrono::NaiveDate::from_ymd_opt(2020, 4, 2)
5756
.unwrap()
@@ -67,7 +66,6 @@ fn generate_events() -> Vec<SoonToBeIcsEvent> {
6766
},
6867
SoonToBeIcsEvent {
6968
name: "BTI5-VSP/01".to_owned(),
70-
pretty_name: "BTI5-VSP/01".to_owned(),
7169
status: EventStatus::Confirmed,
7270
start_time: chrono::NaiveDate::from_ymd_opt(2020, 5, 14)
7371
.unwrap()
@@ -159,7 +157,7 @@ fn remove_event_gets_emoji_prefix() {
159157
};
160158
apply_change(&mut events, date, change, RemovedEvents::Emoji);
161159
assert_eq!(events.len(), 2);
162-
assert_eq!(events[1].pretty_name, "🚫 BTI5-VSP/01");
160+
assert_eq!(events[1].name, "🚫 BTI5-VSP/01");
163161
}
164162

165163
#[test]
@@ -177,7 +175,7 @@ fn namesuffix_is_added() {
177175
room: None,
178176
};
179177
apply_change(&mut events, date, change, RemovedEvents::Cancelled);
180-
assert_eq!(events[1].pretty_name, "BTI5-VSP/01 whatever");
178+
assert_eq!(events[1].name, "BTI5-VSP/01 whatever");
181179
}
182180

183181
#[test]

src/apply_details.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub fn apply_details(event: &mut SoonToBeIcsEvent, details: &EventDetails) {
1919
fn create_event(description: &str) -> SoonToBeIcsEvent {
2020
SoonToBeIcsEvent {
2121
name: "BTI5-VSP/01".to_owned(),
22-
pretty_name: "BTI5-VSP/01".to_owned(),
2322
status: crate::generate_ics::EventStatus::Confirmed,
2423
start_time: chrono::NaiveDate::from_ymd_opt(2020, 4, 2)
2524
.unwrap()

src/events.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ impl From<EventEntry> for SoonToBeIcsEvent {
3535
Self {
3636
start_time: event.start_time,
3737
end_time: event.end_time,
38-
name: event.name.clone(),
39-
pretty_name: event.name,
38+
name: event.name,
4039
status: EventStatus::Confirmed,
4140
alert_minutes_before: None,
4241
description: event.description,

src/generate_ics.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub enum EventStatus {
1313
#[derive(Debug, PartialEq, Eq, Hash)]
1414
pub struct SoonToBeIcsEvent {
1515
pub name: String,
16-
pub pretty_name: String,
1716
pub status: EventStatus,
1817
pub start_time: NaiveDateTime,
1918
pub end_time: NaiveDateTime,
@@ -82,7 +81,7 @@ fn event_as_ics_vevent_string(output: &mut String, event: &SoonToBeIcsEvent) {
8281
_ = writeln!(
8382
output,
8483
"SUMMARY:{}",
85-
string_to_ical_escaped_text(&event.pretty_name)
84+
string_to_ical_escaped_text(&event.name)
8685
);
8786
_ = writeln!(
8887
output,
@@ -183,7 +182,6 @@ fn parse_ics_date() {
183182
fn create_minimal_event_vevent() {
184183
let event = SoonToBeIcsEvent {
185184
name: "BTI5-VS".to_owned(),
186-
pretty_name: "BTI5-VS".to_owned(),
187185
status: EventStatus::Cancelled,
188186
start_time: chrono::NaiveDate::from_ymd_opt(2020, 8, 22)
189187
.unwrap()
@@ -202,7 +200,7 @@ fn create_minimal_event_vevent() {
202200
event_as_ics_vevent_string(&mut result, &event);
203201
assert_eq!(
204202
result,
205-
"BEGIN:VEVENT\nTRANSP:OPAQUE\nSTATUS:CANCELLED\nSUMMARY:BTI5-VS\nDTSTART;TZID=Europe/Berlin:20200822T083000\nDTEND;TZID=Europe/Berlin:20200822T113000\nURL;VALUE=URI:https://telegram.me/HAWHHCalendarBot\nUID:dbbd48a01ce77b8c@calendarbot.hawhh.de\nEND:VEVENT\n"
203+
"BEGIN:VEVENT\nTRANSP:OPAQUE\nSTATUS:CANCELLED\nSUMMARY:BTI5-VS\nDTSTART;TZID=Europe/Berlin:20200822T083000\nDTEND;TZID=Europe/Berlin:20200822T113000\nURL;VALUE=URI:https://telegram.me/HAWHHCalendarBot\nUID:c2238d8b06ddebc8@calendarbot.hawhh.de\nEND:VEVENT\n"
206204
);
207205
}
208206

0 commit comments

Comments
 (0)