-
Notifications
You must be signed in to change notification settings - Fork 38
fixed offset #1943
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
fixed offset #1943
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -344,7 +344,7 @@ pub struct UpdatePackageVisibility { | |||||||||||||||||||||||||||||||||||||
| pub struct ListPackages { | ||||||||||||||||||||||||||||||||||||||
| pub ident: BuilderPackageIdent, | ||||||||||||||||||||||||||||||||||||||
| pub visibility: Vec<PackageVisibility>, | ||||||||||||||||||||||||||||||||||||||
| pub page: i64, | ||||||||||||||||||||||||||||||||||||||
| pub offset: i64, | ||||||||||||||||||||||||||||||||||||||
| pub limit: i64, | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
@@ -619,72 +619,77 @@ impl Package { | |||||||||||||||||||||||||||||||||||||
| let name_str = pl.ident.name.clone(); | ||||||||||||||||||||||||||||||||||||||
| let parts = pl.ident.clone().parts(); | ||||||||||||||||||||||||||||||||||||||
| let visibility = pl.visibility.clone(); | ||||||||||||||||||||||||||||||||||||||
| let page = pl.page; | ||||||||||||||||||||||||||||||||||||||
| let offset_val = pl.offset; | ||||||||||||||||||||||||||||||||||||||
| let limit = pl.limit; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| let mut query = packages_with_channel_platform::table | ||||||||||||||||||||||||||||||||||||||
| .filter(packages_with_channel_platform::origin.eq(origin_str)) | ||||||||||||||||||||||||||||||||||||||
| let mut base_query = packages_with_channel_platform::table | ||||||||||||||||||||||||||||||||||||||
| .filter(packages_with_channel_platform::origin.eq(origin_str.clone())) | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| .filter(packages_with_channel_platform::origin.eq(origin_str.clone())) | |
| .filter(packages_with_channel_platform::origin.eq(&origin_str)) |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name_str variable is cloned twice (lines 633 and 659). Consider reusing the reference or restructuring to avoid unnecessary clones.
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two branches (limit < 0 and limit >= 0) have inconsistent deduplication methods. The first branch uses .unique() while the second uses .unique_by(|p| (p.ident.clone(), p.origin.clone())). This inconsistency could lead to different results between paginated and non-paginated queries. Use the same deduplication key for both branches.
| pkgs = pkgs.into_iter().unique().collect(); | |
| pkgs = pkgs.into_iter().unique_by(|p| (p.ident.clone(), p.origin.clone())).collect(); |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loading all records into memory for pagination defeats the purpose of database-level pagination. This approach will not scale well with large datasets and could cause memory issues. Consider implementing cursor-based pagination or using SQL window functions to maintain deduplication while paginating at the database level.
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The logic for handling limit < 0 is inconsistent with the list() method. In list(), negative limits are checked at line 640, but here the negative check is embedded within the end calculation. Consider extracting this into an early return pattern like in list() for consistency.
| let start = offset_val as usize; | |
| let end = if limit < 0 { | |
| unique_by_name.len() | |
| } else { | |
| (start + limit as usize).min(unique_by_name.len()) | |
| }; | |
| if limit < 0 { | |
| // Early return: negative limit means return all results | |
| let results = unique_by_name.clone(); | |
| let duration_millis = start_time.elapsed().as_millis(); | |
| trace!("DBCall package::list_distinct_for_origin time: {} ms", | |
| duration_millis); | |
| Histogram::DbCallTime.set(duration_millis as f64); | |
| Histogram::PackageListDistinctForOriginCallTime.set(duration_millis as f64); | |
| return Ok((results, total_count)); | |
| } | |
| let start = offset_val as usize; | |
| let end = (start + limit as usize).min(unique_by_name.len()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Multiple type conversions between i64, isize, and usize create confusion and potential overflow risks. The start variable is i64, then converted to isize here, while earlier conversions also occur. Consider standardizing on a single type throughout the pagination logic to reduce conversion overhead and improve clarity.