Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tech] Calendar deduplication #476

Merged
merged 4 commits into from
Nov 22, 2019

Conversation

patochectp
Copy link
Member

No description provided.

src/model.rs Outdated
@@ -777,6 +777,39 @@ impl Collections {
}
self.vehicle_journeys = CollectionWithId::new(vehicle_journeys).unwrap();
}

/// Many calendars are identicall and can be deduplicate
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Many calendars are identicall and can be deduplicate
/// Many calendars are identical and can be deduplicate

src/model.rs Outdated

let mut calendars_used: Vec<Calendar> = vec![];
let mut vehicle_journeys = self.vehicle_journeys.take();
vehicle_journeys.sort_unstable_by_key(|vj| vj.id.clone());
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand why you need to sort the vehicle_journeys by id? vehicle_journeys and calendars are both stored in CollectionWithId which are already ordered and the order is not gonna be altered (only some elements are gonna be removed, but relative positions are gonna be the same). Or am I missing something?

If I am missing something and the sorting needs to stay, please consider the following solution to avoid the .clone() operation.

Suggested change
vehicle_journeys.sort_unstable_by_key(|vj| vj.id.clone());
vehicle_journeys.sort_unstable_by(|vj_a, vj_b| {
vj_a.service_id
.partial_cmp(&vj_b.service_id)
.unwrap_or(std::cmp::Ordering::Equal)
});

Copy link
Member

Choose a reason for hiding this comment

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

why not vehicle_journeys.sort_unstable_by(|vj1, vj2| vj1.service_id.cmp(&vj2.service_id)); ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, why not? That's obviously better than mine! No reason, just didn't look deep enough I guess.

src/model.rs Outdated
Comment on lines 787 to 792
for c in calendars {
if c.dates == *dates {
return Some(c);
}
}
None
Copy link
Contributor

Choose a reason for hiding this comment

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

This part could be written with the following syntax too.

calendars.iter().filter(|c| c.dates == *dates).next()

This is shorter and might allow to remove the find_duplicate_calendar function and put the code directly inline. If you prefer to keep the find_duplicate_calendar, then maybe the for-loop is more readable?

Copy link
Member

Choose a reason for hiding this comment

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

calendars.iter().find(|c| c.dates == *dates)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes, once again, you caught it. Maybe one day I'll think about it!

@ArnaudOggy ArnaudOggy changed the title Calendar deduplication [tech] Calendar deduplication Nov 21, 2019
@patochectp patochectp force-pushed the calendar_deduplication branch from 3164c9c to 29cc444 Compare November 21, 2019 15:47
@datanel datanel force-pushed the calendar_deduplication branch from 29cc444 to 4ed96f3 Compare November 22, 2019 07:19
@mergify mergify bot merged commit 64a8f3a into hove-io:master Nov 22, 2019
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