-
Notifications
You must be signed in to change notification settings - Fork 73
feat: create post/put bsos postgres #1911
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
base: master
Are you sure you want to change the base?
Conversation
cb05820 to
4bfd8ff
Compare
8b7eae1 to
44be220
Compare
44be220 to
c3a4e8a
Compare
| collection_id, | ||
| collection: params.collection, | ||
| }) | ||
| .await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already called in put_bso.
| ) -> Result<results::PostBsos, Self::Error> { | ||
| todo!() | ||
| async fn post_bsos(&mut self, params: params::PostBsos) -> DbResult<results::PostBsos> { | ||
| let collection_id = self.get_or_create_collection_id(¶ms.collection).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have the collection id here, let's pass it to put_bso instead of repeatedly call get_or_create_collection there.
c3a4e8a to
3e37fec
Compare
| todo!() | ||
| let collection_id = self.get_or_create_collection_id(¶ms.collection).await?; | ||
| let modified = self.timestamp(); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why couldn't we have a quota check here and error out early?
| payload: if bso.payload.is_some() { | ||
| Some(payload) | ||
| } else { | ||
| None | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| payload: if bso.payload.is_some() { | |
| Some(payload) | |
| } else { | |
| None | |
| }, | |
| payload: bso.payload.as_deref(), |
| // original required millisecond conversion | ||
| let expiry_ts = SyncTimestamp::from_i64(timestamp + (i64::from(ttl) * 1000))?; | ||
| let modified_ts = SyncTimestamp::from_i64(timestamp)?; | ||
|
|
||
| let expiry_dt = expiry_ts.as_naive_datetime()?; | ||
| let modified_dt = modified_ts.as_naive_datetime()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is simpler/more explicit going through chrono:
| // original required millisecond conversion | |
| let expiry_ts = SyncTimestamp::from_i64(timestamp + (i64::from(ttl) * 1000))?; | |
| let modified_ts = SyncTimestamp::from_i64(timestamp)?; | |
| let expiry_dt = expiry_ts.as_naive_datetime()?; | |
| let modified_dt = modified_ts.as_naive_datetime()?; | |
| let modified = self.timestamp().as_naive_datetime()?; | |
| let expiry = modified_dt + TimeDelta::seconds(ttl as i64); |
| #[derive(AsChangeset)] | ||
| #[diesel(table_name = bsos)] | ||
| pub struct BsoChangeset<'a> { | ||
| pub sortindex: Option<Option<i32>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you're able to actually NULL out sortindex on update
| pub sortindex: Option<Option<i32>>, | |
| pub sortindex: Option<i32>, |
| expiry: if bso.ttl.is_some() { | ||
| Some(expiry_dt) | ||
| } else { | ||
| None | ||
| }, | ||
| modified: if bso.payload.is_some() || bso.sortindex.is_some() { | ||
| Some(modified_dt) | ||
| } else { | ||
| None | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you could use map and/or then_some for these
| expiry: if bso.ttl.is_some() { | |
| Some(expiry_dt) | |
| } else { | |
| None | |
| }, | |
| modified: if bso.payload.is_some() || bso.sortindex.is_some() { | |
| Some(modified_dt) | |
| } else { | |
| None | |
| }, | |
| modified: (bso.payload.is_some() || bso.sortindex.is_some()).then_some(modified), | |
| expiry: bso.ttl.map(|_| expiry_dt), |
Description
Implement logic to
putandposttobsostable.Issue(s)
Closes STOR-339.