Profiles: bound range iterations by profile id

When iterating over submissions for a profile, previously
it was possible to iterate past the end of a given profile's
submissions, and into the next profile's. This was fixed by
setting lower & upper bounds rather than leaving them
open-ended
This commit is contained in:
asonix 2021-01-24 20:02:03 -06:00
parent b1d2664c84
commit 820e948acd
2 changed files with 47 additions and 25 deletions

View file

@ -264,9 +264,9 @@ impl Store {
})
.into_iter()
.flat_map(move |published| {
let range_start = published_submission_range_start(published);
let range_start = range_start.as_bytes().to_vec();
this.published_date_range(range_start..)
let range_entry = published_submission_range_start(published);
let range_entry = range_entry.as_bytes().to_vec();
this.published_date_range(range_entry..)
})
}
@ -281,9 +281,9 @@ impl Store {
})
.into_iter()
.flat_map(move |published| {
let range_end = published_submission_range_start(published);
let range_end = range_end.as_bytes().to_vec();
this.published_date_range(..range_end)
let range_entry = published_submission_range_start(published);
let range_entry = range_entry.as_bytes().to_vec();
this.published_date_range(..range_entry)
})
.rev()
}
@ -320,9 +320,9 @@ impl Store {
self.extract(id, |s| Some((s.profile_id, s.drafted_at)))
.into_iter()
.flat_map(move |(profile_id, drafted)| {
let range_start = profile_id_drafted_submission_range_start(profile_id, drafted);
let range_start = range_start.as_bytes().to_vec();
this.drafted_date_range_for_profile(range_start..)
let range_end = profile_id_drafted_submission_range_end(profile_id);
let range_entry = profile_id_drafted_submission_range_entry(profile_id, drafted);
this.drafted_date_range_for_profile(range_entry..range_end)
})
}
@ -335,9 +335,9 @@ impl Store {
self.extract(id, |s| Some((s.profile_id, s.drafted_at)))
.into_iter()
.flat_map(move |(profile_id, drafted)| {
let range_end = profile_id_drafted_submission_range_start(profile_id, drafted);
let range_end = range_end.as_bytes().to_vec();
this.drafted_date_range_for_profile(..range_end)
let range_start = profile_id_drafted_submission_range_beginning(profile_id);
let range_entry = profile_id_drafted_submission_range_entry(profile_id, drafted);
this.drafted_date_range_for_profile(range_start..range_entry)
})
.rev()
}
@ -374,10 +374,9 @@ impl Store {
self.extract(id, |s| s.published.map(|p| (s.profile_id, p)))
.into_iter()
.flat_map(move |(profile_id, published)| {
let range_start =
profile_id_published_submission_range_start(profile_id, published);
let range_start = range_start.as_bytes().to_vec();
this.published_date_range_for_profile(range_start..)
let range_end = profile_id_publshed_submission_range_end(profile_id);
let range_entry = profile_id_publshed_submission_range_entry(profile_id, published);
this.published_date_range_for_profile(range_entry..range_end)
})
}
@ -390,9 +389,9 @@ impl Store {
self.extract(id, |s| s.published.map(|p| (s.profile_id, p)))
.into_iter()
.flat_map(move |(profile_id, published)| {
let range_end = profile_id_published_submission_range_start(profile_id, published);
let range_end = range_end.as_bytes().to_vec();
this.published_date_range_for_profile(..range_end)
let range_start = profile_id_publshed_submission_range_beginning(profile_id);
let range_entry = profile_id_publshed_submission_range_entry(profile_id, published);
this.published_date_range_for_profile(range_start..range_entry)
})
.rev()
}
@ -499,7 +498,11 @@ fn profile_id_drafted_submission_key(
)
}
fn profile_id_drafted_submission_range_start(
fn profile_id_drafted_submission_range_beginning(profile_id: Uuid) -> String {
format!("/profile/{}/drafted/", profile_id)
}
fn profile_id_drafted_submission_range_entry(
profile_id: Uuid,
drafted_at: DateTime<Utc>,
) -> String {
@ -510,6 +513,10 @@ fn profile_id_drafted_submission_range_start(
)
}
fn profile_id_drafted_submission_range_end(profile_id: Uuid) -> String {
format!("/profile/{}/draftee/", profile_id)
}
fn published_profile_submission_key(
profile_id: Uuid,
published: DateTime<Utc>,
@ -535,7 +542,11 @@ fn published_submission_range_start(published: DateTime<Utc>) -> String {
format!("/published/{}", published.to_rfc3339())
}
fn profile_id_published_submission_range_start(
fn profile_id_publshed_submission_range_beginning(profile_id: Uuid) -> String {
format!("/profile/{}/published/", profile_id)
}
fn profile_id_publshed_submission_range_entry(
profile_id: Uuid,
published: DateTime<Utc>,
) -> String {
@ -546,6 +557,10 @@ fn profile_id_published_submission_range_start(
)
}
fn profile_id_publshed_submission_range_end(profile_id: Uuid) -> String {
format!("/profile/{}/publishee/", profile_id)
}
fn profile_id_submission_count_key(profile_id: Uuid) -> String {
format!("/profile/{}/count", profile_id)
}

View file

@ -19,6 +19,10 @@ struct NotificationKeys {
}
impl NotificationKeys {
fn notification_start(&self, profile_id: Uuid) -> String {
format!("/profiles/{}/created/", profile_id)
}
fn notification_key(
&self,
profile_id: Uuid,
@ -34,6 +38,10 @@ impl NotificationKeys {
)
}
fn notification_end(&self, profile_id: Uuid) -> String {
format!("/profile/{}/createe/", profile_id)
}
fn date_key(&self, profile_id: Uuid, notification_id: Uuid) -> String {
format!(
"/profile/{}/{}/{}",
@ -321,9 +329,8 @@ impl NotificationStore {
let keys = keys.clone();
self.notifications
.range(
..keys
.notification_key(profile_id, date, notification_id)
.as_bytes(),
keys.notification_start(profile_id)
..keys.notification_key(profile_id, date, notification_id),
)
.values()
.filter_map(|res| res.ok())
@ -349,7 +356,7 @@ impl NotificationStore {
self.notifications
.range(
keys.notification_key(profile_id, date, notification_id)
.as_bytes()..,
..keys.notification_end(profile_id),
)
.values()
.filter_map(|res| res.ok())