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

Disable default ordering in GraphQL queries #5380

Merged
merged 4 commits into from
Jan 8, 2025

Conversation

LucasG0
Copy link
Contributor

@LucasG0 LucasG0 commented Jan 6, 2025

Implements #5376
Later PR will come to support it within SDK

@github-actions github-actions bot added the group/backend Issue related to the backend (API Server, Git Agent) label Jan 6, 2025
Copy link

codspeed-hq bot commented Jan 6, 2025

CodSpeed Performance Report

Merging #5380 will not alter performance

Comparing dga-20250103-node-list-order (5a4d686) with stable (c67b7a0)

Summary

✅ 10 untouched benchmarks

@LucasG0 LucasG0 force-pushed the dga-20250103-node-list-order branch 2 times, most recently from 772f747 to b9e863d Compare January 6, 2025 13:30
@LucasG0 LucasG0 marked this pull request as ready for review January 6, 2025 14:03
@LucasG0 LucasG0 requested a review from a team January 6, 2025 14:04
Copy link
Collaborator

@dgarros dgarros left a comment

Choose a reason for hiding this comment

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

Great work.
Instead of passing a dict to the function I think it would be best to use a proper dataclass or Pydantic model this way it will be easier to support additional option in the future.

@LucasG0 LucasG0 force-pushed the dga-20250103-node-list-order branch from b9e863d to 5eb2d19 Compare January 6, 2025 17:48
@LucasG0 LucasG0 force-pushed the dga-20250103-node-list-order branch from 5eb2d19 to 24270c2 Compare January 6, 2025 18:17
@LucasG0 LucasG0 requested a review from dgarros January 6, 2025 18:17
@@ -901,8 +918,8 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
self.params["uuid"] = self.filters["id"]
elif not self.has_filters and not self.schema.order_by:
use_simple = True
self.order_by = ["n.uuid"]

if self.order is None or self.order.disable is not True:
Copy link
Collaborator

Choose a reason for hiding this comment

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

this logic looks surprising to me ...

continue
self.order_by.append(far.node_value_query_variable)
self.order_by.append("n.uuid")
if should_order:
Copy link
Collaborator

Choose a reason for hiding this comment

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

even if the order is disabled we should also order by uuid to guarantee the pagination

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I did not have that in mind

Copy link
Contributor

Choose a reason for hiding this comment

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

Some additional context for the self.order_by.append("n.uuid"): #4704

if far.supports_profile:
self.order_by.append(far.final_value_query_variable)
continue
self.order_by.append(far.node_value_query_variable)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I let this block within should_order branch condition as this block seems only related to ordering.

@LucasG0 LucasG0 requested a review from dgarros January 7, 2025 09:38
@LucasG0 LucasG0 force-pushed the dga-20250103-node-list-order branch from 936b255 to 47bcab8 Compare January 7, 2025 09:39
@LucasG0 LucasG0 force-pushed the dga-20250103-node-list-order branch from 47bcab8 to 3f53022 Compare January 7, 2025 13:47
use_simple = True
self.add_to_query(" AND n.uuid = $uuid")
return
if not self.has_filters and not self.schema.order_by:
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we also check if order is disabled here and exit early ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this condition is met, we set self.order_by to ["n.uuid"] in order to guarantee pagination, and we exit early. As schema.order_by is empty, it feels like we do not even need to check for order?

@LucasG0 LucasG0 force-pushed the dga-20250103-node-list-order branch 2 times, most recently from f5a8a5f to 928bb42 Compare January 8, 2025 12:17
@LucasG0 LucasG0 force-pushed the dga-20250103-node-list-order branch from 928bb42 to 5a4d686 Compare January 8, 2025 12:19
Copy link
Collaborator

@dgarros dgarros left a comment

Choose a reason for hiding this comment

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

great work

@LucasG0 LucasG0 merged commit 10f150b into stable Jan 8, 2025
34 checks passed
@LucasG0 LucasG0 deleted the dga-20250103-node-list-order branch January 8, 2025 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
group/backend Issue related to the backend (API Server, Git Agent)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants