Skip to content

Commit

Permalink
chore: standardize custom image list size
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterPtato committed Apr 17, 2024
1 parent f7ae90b commit ddbd53e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions svc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion svc/pkg/linode/standalone/gc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ async fn run_for_linode_account(
.into_iter()
.map(|x| x.id)
.collect::<Vec<_>>();
if image_ids.len() == 100 {
if image_ids.len() == util_linode::api::CUSTOM_IMAGE_LIST_SIZE {
// We don't need to paginate since we'll never have more than
// `number of regions * number of pools * 2` images which is not more than 500 (x2 is for the old +
// new images)
tracing::warn!("page limit reached, new images may not be returned");
}

Expand Down
14 changes: 13 additions & 1 deletion svc/pkg/linode/util/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ pub async fn delete_custom_image(client: &Client, image_id: &str) -> GlobalResul
client.delete(&format!("/images/{image_id}")).await
}

pub const CUSTOM_IMAGE_LIST_SIZE: usize = 500;

#[derive(Deserialize)]
pub struct ListCustomImagesResponse {
pub data: Vec<CustomImage>,
Expand All @@ -444,8 +446,18 @@ pub struct CustomImage {
pub async fn list_custom_images(client: &Client) -> GlobalResult<Vec<CustomImage>> {
tracing::info!("listing custom images");

let res = client.get::<ListCustomImagesResponse>("/images").await?;
let req = client
.inner()
.get("https://api.linode.com/v4/images")
.query(&[("page_size", CUSTOM_IMAGE_LIST_SIZE)]);

let res = client
.request(req, None, false)
.await?
.json::<ListCustomImagesResponse>()
.await?;

// Can't use `X-Filter` on `created_by`, filter manually
Ok(res
.data
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions svc/pkg/linode/util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use reqwest::header;
use rivet_operation::prelude::*;
use serde::{de::DeserializeOwned, Deserialize};

pub mod consts;
pub mod api;
pub mod consts;

#[derive(Clone)]
pub struct Client {
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Client {
&self.inner
}

async fn request(
pub async fn request(
&self,
req: reqwest::RequestBuilder,
body: Option<serde_json::Value>,
Expand Down

0 comments on commit ddbd53e

Please sign in to comment.