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

feat: Sort collection API #888

Merged
merged 4 commits into from
Sep 6, 2022
Merged

feat: Sort collection API #888

merged 4 commits into from
Sep 6, 2022

Conversation

Jagrutiti
Copy link
Member

What

  • The instruction of the PR is here:

by default, always sort on freshest item (higher id ?) first

Part of

@Jagrutiti Jagrutiti requested a review from a team as a code owner September 3, 2022 08:22
@codecov
Copy link

codecov bot commented Sep 3, 2022

Codecov Report

Merging #888 (069dabd) into master (1e63ca2) will increase coverage by 7.56%.
The diff coverage is 73.92%.

@@            Coverage Diff             @@
##           master     #888      +/-   ##
==========================================
+ Coverage   44.73%   52.29%   +7.56%     
==========================================
  Files          96       92       -4     
  Lines        6981     6958      -23     
==========================================
+ Hits         3123     3639     +516     
+ Misses       3858     3319     -539     
Impacted Files Coverage Δ
robotoff/cli/batch.py 0.00% <ø> (ø)
robotoff/cli/insights.py 0.00% <0.00%> (ø)
robotoff/insights/dataclass.py 100.00% <ø> (ø)
robotoff/prediction/ocr/brand.py 68.62% <0.00%> (ø)
robotoff/prediction/ocr/expiration_date.py 25.71% <ø> (ø)
robotoff/prediction/ocr/image_flag.py 41.02% <ø> (ø)
robotoff/prediction/ocr/label.py 72.30% <0.00%> (ø)
robotoff/prediction/ocr/packager_code.py 73.07% <ø> (ø)
robotoff/prediction/ocr/product_weight.py 49.10% <0.00%> (+1.28%) ⬆️
robotoff/products.py 42.75% <ø> (+2.26%) ⬆️
... and 61 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment on lines 137 to 138
else:
query = query.order_by(ProductInsight.id.desc())
Copy link
Member

Choose a reason for hiding this comment

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

As said in meeting: better not introduce a default sorting in a widely used function, it might have unexpected side effects.

We should instead use order_by="most_recent" in Collection view and implement it here.

Also you should use timestamp here and not id, because id is special on ProductInsight (it's not numerical, it's a uuid).

@@ -363,6 +369,8 @@ def get_logo_annotation(
if offset is not None:
query = query.offset(offset)

# query = query.order_by(LogoAnnotation.image_prediction.timestamp.desc())
Copy link
Member

Choose a reason for hiding this comment

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

here you can use LogoAnnotation.id for order_by. id exists because it's automatically added by peewee.

See https://docs.peewee-orm.com/en/latest/peewee/models.html#fields

In the above example, because none of the fields are initialized with primary_key=True, an auto-incrementing primary key will automatically be created and named “id”. Peewee uses AutoField to signify an auto-incrementing integer primary key, which implies primary_key=True.

Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

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

Kudos.

You need to resolve conflicts and we should be able to merge.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 5, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot C 1 Security Hotspot
Code Smell A 108 Code Smells

0.0% 0.0% Coverage
0.1% 0.1% Duplication

@alexgarel alexgarel merged commit 275ef95 into master Sep 6, 2022
@alexgarel alexgarel deleted the sort-collection-api branch September 6, 2022 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants