Skip to content

Conversation

@taddes
Copy link
Collaborator

@taddes taddes commented Dec 4, 2025

Description

Implement logic to put and post to bsos table.

Issue(s)

Closes STOR-339.

@taddes taddes self-assigned this Dec 4, 2025
@taddes taddes changed the title [WIP} feat: create post/put bsos postgres [WIP] feat: create post/put bsos postgres Dec 4, 2025
@taddes taddes force-pushed the feat/create-post-bsos-postgres-STOR-339 branch 2 times, most recently from cb05820 to 4bfd8ff Compare December 5, 2025 16:28
@taddes taddes marked this pull request as ready for review December 5, 2025 16:28
@taddes taddes requested a review from pjenvey December 5, 2025 17:39
@taddes taddes changed the title [WIP] feat: create post/put bsos postgres feat: create post/put bsos postgres Dec 5, 2025
@taddes taddes force-pushed the feat/create-post-bsos-postgres-STOR-339 branch from 8b7eae1 to 44be220 Compare December 8, 2025 15:56
@taddes taddes requested a review from chenba December 8, 2025 15:56
@taddes taddes mentioned this pull request Dec 8, 2025
@taddes taddes force-pushed the feat/create-post-bsos-postgres-STOR-339 branch from 44be220 to c3a4e8a Compare December 8, 2025 18:33
collection_id,
collection: params.collection,
})
.await?;
Copy link
Collaborator

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(&params.collection).await?;
Copy link
Collaborator

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.

@taddes taddes force-pushed the feat/create-post-bsos-postgres-STOR-339 branch from c3a4e8a to 3e37fec Compare December 8, 2025 19:58
todo!()
let collection_id = self.get_or_create_collection_id(&params.collection).await?;
let modified = self.timestamp();

Copy link
Collaborator

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?

Comment on lines +482 to +486
payload: if bso.payload.is_some() {
Some(payload)
} else {
None
},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
payload: if bso.payload.is_some() {
Some(payload)
} else {
None
},
payload: bso.payload.as_deref(),

Comment on lines +467 to +472
// 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()?;
Copy link
Member

@pjenvey pjenvey Dec 8, 2025

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:

Suggested change
// 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>>,
Copy link
Member

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

Suggested change
pub sortindex: Option<Option<i32>>,
pub sortindex: Option<i32>,

Comment on lines +487 to +496
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
},
Copy link
Member

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

Suggested change
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),

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.

4 participants