Skip to content
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

fix: Break out of the loop when we reach cursor limit for list_release_files #1337

Merged
merged 1 commit into from Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Make clippy happy"

.iter()
.find(|&cfg| cfg.to_lowercase() == name)
.map(|v| v.as_ref())
}
}

Expand Down