Marking the last piece of data on each page is a duplicate issue, which can be solved by adding the id field to the order by rig and using a unique field (#9799)

Signed-off-by: root <root@localhost.localdomain>
Co-authored-by: root <root@localhost.localdomain>
This commit is contained in:
yuanboao 2024-10-25 15:34:58 +08:00 committed by GitHub
parent 60ddcdf960
commit 4693080ce0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -132,14 +132,14 @@ class AppAnnotationService:
MessageAnnotation.content.ilike("%{}%".format(keyword)), MessageAnnotation.content.ilike("%{}%".format(keyword)),
) )
) )
.order_by(MessageAnnotation.created_at.desc()) .order_by(MessageAnnotation.created_at.desc(), MessageAnnotation.id.desc())
.paginate(page=page, per_page=limit, max_per_page=100, error_out=False) .paginate(page=page, per_page=limit, max_per_page=100, error_out=False)
) )
else: else:
annotations = ( annotations = (
db.session.query(MessageAnnotation) db.session.query(MessageAnnotation)
.filter(MessageAnnotation.app_id == app_id) .filter(MessageAnnotation.app_id == app_id)
.order_by(MessageAnnotation.created_at.desc()) .order_by(MessageAnnotation.created_at.desc(), MessageAnnotation.id.desc())
.paginate(page=page, per_page=limit, max_per_page=100, error_out=False) .paginate(page=page, per_page=limit, max_per_page=100, error_out=False)
) )
return annotations.items, annotations.total return annotations.items, annotations.total