Skip to content

Commit

Permalink
Fix: Unneeded branching around a continue statement;
Browse files Browse the repository at this point in the history
Fix: Return correct Retry-After on ratelimit
  • Loading branch information
TobiasDeBruijn committed Jul 22, 2024
1 parent 58d640e commit 29fb215
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
5 changes: 2 additions & 3 deletions frontend/src/components/UploadPhotoDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ export default Vue.extend({
if(e instanceof TooManyRequests) {
console.log(`Got HTTP 429. Waiting ${e.retryAfter} seconds`);
await new Promise(resolve => setTimeout(resolve, e.retryAfter));
continue;
} else {
continue;
}
continue;
}
if(result === true) {
Expand Down
17 changes: 8 additions & 9 deletions server/chroma/src/routes/v1/photo/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use actix_multiresponse::Payload;
use dal::database::{Album, Database, Photo, PhotoQuality};
use dal::storage_engine::Storage;
use exif::{In, Tag};
use governor::clock::Clock;
use image::imageops::FilterType;
use image::io::Reader;
use image::{DynamicImage, GenericImageView};
Expand Down Expand Up @@ -47,7 +48,7 @@ pub async fn create(
}

// TODO Update actix-multiresponse to support moving out the payload, avoids another clone
let photo_id = image_pipeline(&data, payload.photo_data.clone(), &album, &data.db).await?;
let photo_id = image_pipeline(&data, payload.photo_data.clone(), &album).await?;

Ok(Payload(CreatePhotoResponse { photo_id }))
}
Expand All @@ -58,16 +59,13 @@ pub async fn create(
///
/// If any step in the pipeline fails
#[instrument(skip(data, image))]
async fn image_pipeline(
data: &WebData,
image: Vec<u8>,
album: &Album,
db: &Database,
) -> WebResult<String> {
async fn image_pipeline(data: &WebData, image: Vec<u8>, album: &Album) -> WebResult<String> {
// Make sure we don't run into AWS ratelimits here
if let Err(e) = data.ratelimits.photo_create.check() {
return Err(Error::Ratelimit {
retry_after: e.wait_time_from(e.earliest_possible()).as_secs(),
retry_after: e
.wait_time_from(governor::clock::DefaultClock::default().now())
.as_secs(),
});
}

Expand Down Expand Up @@ -226,7 +224,8 @@ fn resize_and_save(
};

// Fetch the photo
let ok = reqwest::Client::new().get(url)
let ok = reqwest::Client::new()
.get(url)
.send()
.await
.map(|resp| resp.error_for_status().is_ok())
Expand Down

0 comments on commit 29fb215

Please sign in to comment.