-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Conversation
Codecov Report
@@ 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
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
robotoff/app/core.py
Outdated
else: | ||
query = query.order_by(ProductInsight.id.desc()) |
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.
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).
robotoff/app/core.py
Outdated
@@ -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()) |
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.
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.
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.
Kudos.
You need to resolve conflicts and we should be able to merge.
Kudos, SonarCloud Quality Gate passed! |
What
Part of