Skip to content

Commit

Permalink
fix: Break out of the loop when we reach cursor limit for list_releas…
Browse files Browse the repository at this point in the history
…e_files
  • Loading branch information
kamilogorek committed Sep 23, 2022
1 parent 2cac02b commit 324de36
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
23 changes: 17 additions & 6 deletions src/api.rs
Expand Up @@ -502,22 +502,33 @@ impl Api {
PathArg(org),
PathArg(project),
PathArg(release),
QueryArg(cursor),
QueryArg(&cursor),
)
} else {
format!(
"/organizations/{}/releases/{}/files/?cursor={}",
PathArg(org),
PathArg(release),
QueryArg(cursor),
QueryArg(&cursor),
)
};

// TODO(kamil): Instead of breaking out of the loop here when we reach the limit
// (200 pages of 100 items, for a total of 20_000 files), we should send a list of hashes
// to the server, perform an intersection there, and change the upload mechanism
// to leave out only those files that were gave back to us by the server.
// This would also limit number of API requests for deduping from `N=[1:200]` to 1.
let resp = self.get(&path)?;
if resp.status() == 404 || (resp.status() == 400 && !cursor.is_empty()) {
if rv.is_empty() {
return Err(ApiErrorKind::ReleaseNotFound.into());
} else {
break;
}
}

let pagination = resp.pagination();
rv.extend(
resp.convert_rnf::<Vec<Artifact>>(ApiErrorKind::ReleaseNotFound)?
.into_iter(),
);
rv.extend(resp.convert::<Vec<Artifact>>()?.into_iter());
if let Some(next) = pagination.into_next_cursor() {
cursor = next;
} else {
Expand Down
10 changes: 4 additions & 6 deletions src/utils/xcode.rs
Expand Up @@ -182,12 +182,10 @@ impl XcodeProjectInfo {
/// Returns the config with a certain name
pub fn get_configuration(&self, name: &str) -> Option<&str> {
let name = name.to_lowercase();
for cfg in &self.configurations {
if cfg.to_lowercase() == name {
return Some(cfg);
}
}
None
self.configurations
.iter()
.find(|&cfg| cfg.to_lowercase() == name)
.map(|v| v.as_ref())
}
}

Expand Down

0 comments on commit 324de36

Please sign in to comment.